DirectoryEntries.Find Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns a member of this collection.
Overloads
Find(String) |
Returns the member of this collection with the specified name. |
Find(String, String) |
Returns the member of this collection with the specified name and of the specified type. |
Find(String)
- Source:
- DirectoryEntries.cs
- Source:
- DirectoryEntries.cs
- Source:
- DirectoryEntries.cs
- Source:
- DirectoryEntries.cs
Returns the member of this collection with the specified name.
public:
System::DirectoryServices::DirectoryEntry ^ Find(System::String ^ name);
public System.DirectoryServices.DirectoryEntry Find (string name);
member this.Find : string -> System.DirectoryServices.DirectoryEntry
Public Function Find (name As String) As DirectoryEntry
Parameters
- name
- String
Contains the name of the child object for which to search.
Returns
A DirectoryEntry that represents the child object that was found.
Exceptions
The Active Directory Domain Services object is not a container.
An error occurred during the call to the underlying interface.
Remarks
If child objects of different types have the same name, the first matching child object is returned.
Note
The Internet Information Services (IIS) provider does not support this method. Use the overloaded Find method and specify an empty string ("") for the schemaClassName
parameter.
If no matching result is found, a DirectoryServicesCOMException with error code 0x2030 is thrown.
Applies to
Find(String, String)
- Source:
- DirectoryEntries.cs
- Source:
- DirectoryEntries.cs
- Source:
- DirectoryEntries.cs
- Source:
- DirectoryEntries.cs
Returns the member of this collection with the specified name and of the specified type.
public:
System::DirectoryServices::DirectoryEntry ^ Find(System::String ^ name, System::String ^ schemaClassName);
public System.DirectoryServices.DirectoryEntry Find (string name, string? schemaClassName);
public System.DirectoryServices.DirectoryEntry Find (string name, string schemaClassName);
member this.Find : string * string -> System.DirectoryServices.DirectoryEntry
Public Function Find (name As String, schemaClassName As String) As DirectoryEntry
Parameters
- name
- String
The name of the child directory object for which to search.
- schemaClassName
- String
The class name of the child directory object for which to search.
Returns
A DirectoryEntry object that represents the child object that was found.
Exceptions
The Active Directory Domain Services object is not a container.
An error occurred during the call to the underlying interface.
Examples
The following Visual Basic .NET example creates a new DirectoryEntry object with the specified path, then creates a new entry in the container and saves it. It attempts to retrieve the newly created entry.
Try
Dim myEntry1 As DirectoryEntry
Dim myEntry2 As DirectoryEntry
Dim strPath As String = "LDAP://DC=fabrikam,DC=com"
' Create a 'DirectoryEntry' object with the given path.
Dim myDE As New DirectoryEntry(strPath)
Dim myEntries As DirectoryEntries = myDE.Children
' Create a new entry in the container.
myEntry1 = myEntries.Add("CN=Sample Entry", myDE.SchemaClassName)
' Save changes in the 'Active Directory Domain Services' store.
myEntry1.CommitChanges()
' Find a child in the 'DirectoryEntries' collection which has the
' specified name and type.
myEntry2 = myEntries.Find("CN=Sample Entry", myDE.SchemaClassName)
Console.WriteLine(myEntry2.Name + " is found in container.")
Catch e As Exception
Console.WriteLine("The following exception was raised : {0}", e.Message.ToString())
End Try
The following C# example shows how to create a new DirectoryEntry object with the specified path, then creates a new entry in the container and saves it. It attempts to retrieve the newly- created entry.
using System;
using System.DirectoryServices;
class MyClass1
{
static void Main()
{
try
{
DirectoryEntry myEntry1;
DirectoryEntry myEntry2;
String strPath = "LDAP://DC=fabrikam,DC=com";
// Create a 'DirectoryEntry' object with the given path.
DirectoryEntry myDE = new DirectoryEntry(strPath);
DirectoryEntries myEntries = myDE.Children;
// Create a new entry in the container.
myEntry1 = myEntries.Add("CN=Sample Entry",myDE.SchemaClassName);
// Save changes in the 'Active Directory Domain Services' store.
myEntry1.CommitChanges();
// Find a child in the 'DirectoryEntries' collection which has the
// specified name and type.
myEntry2 = myEntries.Find("CN=Sample Entry",myDE.SchemaClassName);
Console.WriteLine (myEntry2.Name + " is found in container.");
}
catch(Exception e)
{
Console.WriteLine("The following exception was raised : {0}",e.Message);
}
}
}
The following C++ example creates a new DirectoryEntry object with the specified path, then creates a new entry in the container and saves it. It attempts to retrieve the new entry.
#using <mscorlib.dll>
#using <System.dll>
#using <System.Directoryservices.dll>
using namespace System;
using namespace System::DirectoryServices;
int main() {
try {
DirectoryEntry* myEntry1;
DirectoryEntry* myEntry2;
String* strPath = S"LDAP://DC=fabrikam,DC=com";
// Create a 'DirectoryEntry' object with the given path.
DirectoryEntry* myDE = new DirectoryEntry(strPath);
DirectoryEntries* myEntries = myDE->Children;
// Create a new entry in the container.
myEntry1 = myEntries->Add(S"CN=Sample Entry", myDE->SchemaClassName);
// Save changes in the 'Active Directory Domain Services' store.
myEntry1->CommitChanges();
// Find a child in the 'DirectoryEntries' collection which has the
// specified name and type.
myEntry2 = myEntries->Find(S"CN=Sample Entry", myDE->SchemaClassName);
Console::WriteLine ("{0} is found in container.", myEntry2->Name);
} catch(Exception* e) {
Console::WriteLine("The following exception was raised : {0}", e->Message);
}
}
Remarks
If no matching result is found, a DirectoryServicesCOMException with error code 0x2030 is thrown.