开发者

How to bind all users in an Active Directory to a dropdown list on a SharePoint site?

I am trying to do what the topic describes and my code so far is:

DirectoryEntry directoryEntry = new DirectoryEntry("LDAP://myDomain/DC=somecollege, DC=someState, DC=edu", myUser, myPassword);
DirectorySearcher directorySearcher = new DirectorySearcher(directoryEntry);
directorySearcher.Filter = "(&(objectCategory=Person))";

SearchResultCollection searchResult = directorySearcher.FindAll();

foreach (SearchResult srUSers in searchResult)
{
    DirectoryEntry de = srUsers.GetDirectoryEntry();
    lbSiteOwnerGroups.Items.Addd(New ListItem(de.Name.ToString()));
}

With this code all persons gets bound to a drop down but the format is: CN=lastName firstName How do I get only the names and not "CN=", I assume I should not need to you string manipulation here.

If I try with de.Path.Tostring() it looks like:

<option value="LDAP://myDomain/CN=DOE John, OU=IT, OU=_someville_NonTeaching, OU=Staff_someville, DC=somecollege, DC=nsw, DC=edu,DC=au">LDAP://myDomain/CN=DOE John, OU=IT, OU=Staff_someville_NonTeaching, OU=Staff_someville, DC=somecollege, DC=fl, DC=edu,DC=com<option>

I have seen I can use de.Properties["mail"].ToStr开发者_运维知识库ing() for example but gives me the error "operator has returned an error". I haven't worked with AD before and I if I get in contact with the AD administrator what questions should I ask him if the questions I have here needs answewer from the actual admin?

Also, there is a subdomain or childdomain that's called Staff, how can I get users from this domain only?

Thanks in advance.


I think it should be like the following code:

foreach (SearchResult srUsers in searchResult)
{
    DirectoryEntry de = srUsers.GetDirectoryEntry();
    lbSiteOwnerGroups.Items.Add(new ListItem(de.Properties["CN"].Value.ToString()));
} 

EDIT

I didn't see the second part of the question. If you want the users from child domain only, you can make your DirectorySearcher binded to the child domain. So, instead of using

LDAP://myDomain/DC=somecollege, DC=someState, DC=edu

You should use something like this

LDAP://childdomain.myDomain/DC=childdomain,DC=somecollege, DC=someState, DC=edu

You need to find out the correct LDAP domain root path for your child domain. I can post more information if you need help on this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜