Searching Active Directory with .NET (Visual Studio 2005)
- Posted: Nov 02, 2005 at 6:56 PM
- 95,609 Views
- 7 Comments
Download
How do I download the videos?
- To download, right click the file type you would like and pick “Save target as…” or “Save link as…”
Why should I download videos from Channel9?
- It's an easy way to save the videos you like locally.
- You can save the videos in order to watch them offline.
- If all you want is to hear the audio, you can download the MP3!
Which version should I choose?
- If you want to view the video on your PC, Xbox or Media Center, download the High Quality WMV file (this is the highest quality version we have available).
- If you'd like a lower bitrate version, to reduce the download time or cost, then choose the Medium Quality WMV file.
- If you have a Zune, WP7, iPhone, iPad, or iPod device, choose the low or medium MP4 file.
- If you just want to hear the audio of the video, choose the MP3 file.
Right click “Save as…”
- Mid Quality WMV (Lo-band, Mobile)
Federal Developer Evangelist, Robert Shelton, takes you through a 12 minute walkthrough/demonstration of how to search Active Directory for users, groups, and other AD Objects.
This demonstration is using the DirectoryServices namespace of the .NET framework. The demonstration is using Visual Studio 2005, but the code will also work as written for Visual Studio 2003.
You can find the code at my blog:
http://sheltonblog.com
My other AD Screencasts:
- Adding user to AD with .NET
http://channel9.msdn.com/Showpost.aspx?postid=130700
- Adding groups and users to groups with .NET
http://channel9.msdn.com/Showpost.aspx?postid=132400
- AD Searchfilter (Querying) Syntax:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adsi/adsi/search_filter_syntax.asp
- List of SearchScope options:
~ Robert Shelton
Comments Closed
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
I'm a VIsual Basic developer. Do you have this project available in Visual Basic code?
Thanks,
David Carpenter
Currently I am working on some web cast for Windows Communication Foundation, otherwise, I would just do it now. After I finish those, I will look at porting all of my screencast to both VB and C#. This way, no one gets left out and it's easier for me, since it is more natural for me to read/write in VB.
Robert
I couldn't find the VB-Code in the net, so I just ported it myself:
' If you want to search in a specific path, here's the right spot.
' Just insert the path into "As New DirectoryEntry("LDAP://OU=Accounting,DC=World,DC=com")"
Dim Entry As New DirectoryEntry
Dim Searcher As New DirectorySearcher(Entry)
Dim AdObj As SearchResult
Searcher.SearchScope = SearchScope.Subtree
Searcher.Filter() = "(ObjectClass=user)"
For Each AdObj In Searcher.FindAll
Label1.Text = Label1.Text & "CN=" & AdObj.Properties("CN").Item(0) & " | Path=" & AdObj.Path & "<br>"
Next
I coded it with ASP.net for a webapplication.
But the App does exactely the same as the first example.
I hope you can use it.
Instead of the common name, I would like to display the users logon name. I have been messing around, I got a look at the target's AD schema, and have found some promising attributes to plug in. However, If I try to use and attribute that is not "mandatory" I get a "ArgumentOutOfRangeException"
Here is my code (almost exact to yours)
DirectoryEntry adDirecEntry = new DirectoryEntry();
DirectorySearcher adDirecSearch = new DirectorySearcher(adDirecEntry);
//set the search scope
adDirecSearch.SearchScope = SearchScope.Subtree;
//Set the filter. For this example we will be looking at all users
adDirecSearch.Filter = "(ObjectClass=user)";
//Execute the search and iterate through the result
//Write results to lboAD for display
foreach (SearchResult adObject in adDirecSearch.FindAll())
{
lboAD.Items.Add(adObject.Properties["uid"][0]);
lboAD.Items.Add(adObject.Path);
}
It is at "lboAD.Items.Add(adObject.Properties["uid"][0]);" that I get the exception. At first I thought it was maybe something else, I dunno what....but it will only display results when I use a mandatory attribute, no matter the ObjectClass.
Is it something to do with my target's AD schema? Is it something I am doing wrong?
Thanks, and again, great work!!
Is there a way to view video in full screen?
adObject.Properties["SAMAccountName"][0]
but i'm using visual studio 2003 & when i run the code it gives me "The specified domain either does not exist or could not be contacted "
so please advice
thanks
Remove this comment
Remove this thread
close