2009-03-06 4 views
1

웹 서비스를 통해 Sharepoint에 이야기 할 때 모든 노력이 도메인 \ 사용자 이름이 필요해 보인다. 예 :Sharepoint에 대화하는 방법 : 나는 단지 성함을 가지고있다.

UserProfileService.GetUserProfileByName(string accountName) 

accountName은 domain \ user name이어야합니다.

전체 이름 (이름 성) 만있는 경우 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; 
} 

답변

1

난 당신이 자신의 계정 이름을 결정하기 위해 사용자의 이름과 성을 위해 Active Directory를 쿼리 할 때 시도 할 수 있다고 가정합니다.

+0

감사합니다. 잘 작동한다. – ira

1

UserGroup.GetAllUserCollectionsFromWeb()을 사용하면 주어진 표시 이름에 대한 로그인 이름을 얻기 위해 결과를 반복 할 수 있습니다.

+0

답변을 읽기 전에 AD에 대한 쿼리가 구현되었습니다. 다른 답변, 제이슨 감사합니다! – ira

1

PeopleEditor 컨트롤을 사용할 수 있습니다.이 컨트롤은 성, 이름 조합을 입력하거나 디렉토리를 탐색 할 수 있습니다.

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을 찾습니다.

+0

감사합니다. Andy! :) – ira

관련 문제