SharePoint와 대화하는 방법 : 전체 이름 만 얻은 경우
-
03-07-2019 - |
문제
웹 서비스를 통해 SharePoint와 대화하는 모든 노력에는 도메인 사용자 이름이 필요합니다. 예를 들어:
UserProfileService.GetUserProfileByName(string accountName)
계정 이름은 도메인 사용자 이름이어야합니다.
전체 이름 (FirstName LastName) 만 얻은 경우 SharePoint와 통신 할 수 있습니까? 전체 이름을 도메인 사용자 이름으로 변환하는 방법이 있습니까? 도메인 사용자 이름이 유일한 방법입니까?
미리 감사드립니다. :)
답변 해주셔서 감사합니다. :)
코드는 다음과 같습니다.
using System.DirectoryServices;
const string ADPATH = "LDAP://myLDAPserver,validUserforAD";
const string USERNAME = "myDomain\\myUserName";
const string PASSWORD = "myPassword";
const string DOMAIN = "myDomain\\";
public static DirectoryEntry GetDirectoryObject()
{
DirectoryEntry directoryObject = new DirectoryEntry(ADPATH, USERNAME, PASSWORD, AuthenticationTypes.Secure);
return directoryObject;
}
public string GetUserNameByCompleteName(string completeName)
{
DirectoryEntry adObject = GetDirectoryObject();
//filter based on complete name
DirectorySearcher searcher = new DirectorySearcher(adObject);
searcher.Filter = "displayname=" + completeName;
SearchResult result = searcher.FindOne();
DirectoryEntry userInfo = result.GetDirectoryEntry();
//getting user name
string userName = (string)userInfo.Properties["samaccountname"].Value ?? string.Empty;
userInfo.Close();
adObject.Close();
return DOMAIN + userName;
}
해결책
계정 이름을 결정하기 위해 사용자의 첫 번째 및 성을 위해 Active Directory를 쿼리하려고 시도 할 수 있다고 생각합니다.
다른 팁
사용해보십시오 UserGroup.GetAllUserCollectionsFromWeb()
, 주어진 디스플레이 이름의 로그인 이름을 얻기 위해 결과를 반복 할 수 있습니다.
당신은 a를 사용할 수 있습니다 PeopleEditor
마지막 이름, FirstName 조합을 입력하거나 디렉토리를 탐색 할 수있는 경우 사용자를 잡을 수 있습니다.
people = new PeopleEditor();
people.MultiSelect = false;
this.Controls.Add(people);
...
int userID = Int32.Parse((((PickerEntity)people.ResolvedEntities[0]).EntityData["SPUserID"]).ToString());
SPUser user = SPContext.Current.Site.RootWeb.SiteUsers.GetByID(userID);
약간 번거롭고 말도 안되지만 작동합니다. 프로그래밍 방식으로 가져와야한다면 Jason이 위에서 말한 것처럼 할 수 있습니다. SPUserCollection
그리고 루프를 통해 SPUser
적절한 디스플레이 이름으로.
제휴하지 않습니다 StackOverflow