This documentation is archived and is not being maintained.

DirectoryEntry Constructor

.NET Framework 1.1

Initializes a new instance of the DirectoryEntry class.

Overload List

Initializes a new instance of the DirectoryEntry class.

[Visual Basic] Public Sub New()
[C#] public DirectoryEntry();
[C++] public: DirectoryEntry();
[JScript] public function DirectoryEntry();

Initializes a new instance of the DirectoryEntry class that binds to the specified native Active Directory object.

[Visual Basic] Public Sub New(Object)
[C#] public DirectoryEntry(object);
[C++] public: DirectoryEntry(Object*);
[JScript] public function DirectoryEntry(Object);

Initializes a new instance of the DirectoryEntry class that binds this instance to the node in Active Directory located at the specified path.

[Visual Basic] Public Sub New(String)
[C#] public DirectoryEntry(string);
[C++] public: DirectoryEntry(String*);
[JScript] public function DirectoryEntry(String);

Initializes a new instance of the DirectoryEntry class. The Path, Username, and Password properties are set to the specified values.

[Visual Basic] Public Sub New(String, String, String)
[C#] public DirectoryEntry(string, string, string);
[C++] public: DirectoryEntry(String*, String*, String*);
[JScript] public function DirectoryEntry(String, String, String);

Initializes a new instance of the DirectoryEntry class. The Path, Username, Password, and AuthenticationType properties are set to the specified values.

[Visual Basic] Public Sub New(String, String, String, AuthenticationTypes)
[C#] public DirectoryEntry(string, string, string, AuthenticationTypes);
[C++] public: DirectoryEntry(String*, String*, String*, AuthenticationTypes);
[JScript] public function DirectoryEntry(String, String, String, AuthenticationTypes);

Example

[Visual Basic, C#, C++] The following example binds a DirectoryEntry to the directory entry at the specified path, and displays the Path of the node's Children.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of the DirectoryEntry constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Public Class PrintChildren
    
    'Entry point which delegates to C-style main Private Function.
    Public Overloads Shared Sub Main()
        Main(System.Environment.GetCommandLineArgs())
    End Sub
    
    Overloads Public Shared Sub Main(args() As String)
        Dim objDE As DirectoryEntry
        Dim strPath As String = "LDAP://DC=onecity,DC=corp,DC=fabrikam,DC=com"
        If args.Length > 0 Then
            strPath = args(1)
        End If 
        ' Create a new DirectoryEntry with the given path.
        objDE = New DirectoryEntry(strPath)
        
        Dim objChildDE As DirectoryEntry
        For Each objChildDE In  objDE.Children
            Console.WriteLine(objChildDE.Path)
        Next objChildDE
    End Sub 'Main
End Class 'PrintChildren 

[C#] 
public class PrintChildren{
   public static void Main(String[] args)
   {
      DirectoryEntry objDE;
      String strPath="LDAP://DC=onecity,DC=corp,DC=fabrikam,DC=com";
      if(args.Length>0)strPath=args[1];
 
      // Create a new DirectoryEntry with the given path.
      objDE=new DirectoryEntry(strPath);
 
      foreach(DirectoryEntry objChildDE in objDE.Children)
        Console.WriteLine(objChildDE.Path);
   }
 }
 

[C++] 
int main()
{
   String* args[] = Environment::GetCommandLineArgs();
   DirectoryEntry* objDE;
   String* strPath=S"LDAP://DC=onecity,DC=corp,DC=fabrikam,DC=com";
   if(args->Length>1)strPath=args[1];

   // Create a new DirectoryEntry with the given path.
   objDE=new DirectoryEntry(strPath);

   System::Collections::IEnumerator* enum0 = objDE->Children->GetEnumerator();
   while (enum0->MoveNext())
   {
      DirectoryEntry* objChildDE = __try_cast<DirectoryEntry*>(enum0->Current);
      Console::WriteLine(objChildDE->Path);
   }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

DirectoryEntry Class | DirectoryEntry Members | System.DirectoryServices Namespace

Show: