Welcome   |  ASP.NET   |  Web Services   |  How Do I...?   |  Class Browser  | WPF Quick Starts
  |   I want my samples in...   

How Do I...? Common Tasks QuickStart Tutorial

Go To...

How Do I...Access Active Directory?

The Active Directory Service Interface (ADSI) accesses the capabilities of directory services from different network providers in a distributed computing environment to present a single set of directory service interfaces for managing network resources. Administrators and developers can use ADSI services to enumerate and manage the resources in a directory service, regardless of which network environment contains the resource. Use Active Directory to perform common administrative tasks, such as locating resources throughout the distributed computing environment.

This sample illustrates how to locate resources in the Active Directory. It is a small console application that can be run from a command prompt. The application takes one command line argument. The first argument has to be a valid path to an Active Directory entry.

Try running the following command, substituting the path for a valid Active Directory path for your particular network:
> ADRead.exe "LDAP://CN=Clarify Operations Team,OU=Distribution Lists,DC=fabricom,DC=com"
In its simplest form, reading from the Active Directory involves:
  1. Creating a new DirectoryEntry:

    		
    DirectoryEntry objDirEnt = new DirectoryEntry(path);
    
    C#


  2. Reading the information from the Active Directory and printing it to the screen:

    		
    string tab = "    ";
    foreach(string key in objDirEnt.Properties.PropertyNames) {
        Console.WriteLine(tab + key + " = ");
        foreach(Object objCollection in objDirEnt.Properties[key])
            Console.WriteLine(tab + tab + objCollection);
    }
    
    
    
    
    C#

Example

C# ADRead.exe
View Source

[This sample can be found at M:\web\users\sites\AspnetQuickStart\v2.0\QuickStart\howto\samples\Services\DirectoryServices\ADRead\
To build this sample, open the SDK command prompt and navigate to the above path. Build the sample using the build tool msbuild passing the solution file as the first parameter: msbuild mySample.sln. The compiled executable will be found in the sub directory \bin directory.]




Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.


Hosted by MaximumASP | Found a broken link? | Contact Us | Terms and conditions | Privacy Policy | Advertise with us
� 2000 - 2010  Mindcracker LLC. All Rights Reserved