DirectoryEntries.Find 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回這個集合的成員。
多載
Find(String) |
傳回具有指定之名稱的這個集合成員。 |
Find(String, String) |
傳回具有指定之名稱和型別的這個集合成員。 |
Find(String)
傳回具有指定之名稱的這個集合成員。
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
參數
- name
- String
包含要搜尋的子物件名稱。
傳回
DirectoryEntry,表示找到的子物件。
例外狀況
Active Directory 網域服務物件不是容器。
呼叫基礎介面期間發生錯誤。
備註
如果不同類型的子物件具有相同的名稱,則會傳回第一個相符的子物件。
注意
Internet Information Services (IIS) 提供者不支援此方法。 使用多載 Find 方法,並針對 參數指定空字串 (“) schemaClassName
。
如果找不到相符的結果, DirectoryServicesCOMException 則會擲回錯誤碼0x2030。
適用於
Find(String, String)
傳回具有指定之名稱和型別的這個集合成員。
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
參數
- name
- String
要搜尋的子目錄物件名稱。
- schemaClassName
- String
要搜尋之子目錄物件的類別 (Class) 名稱。
傳回
DirectoryEntry 物件,表示找到的子物件。
例外狀況
Active Directory 網域服務物件不是容器。
呼叫基礎介面期間發生錯誤。
範例
下列 Visual Basic .NET 範例會使用指定的路徑建立新的 DirectoryEntry 物件,然後在容器中建立新的專案並加以儲存。 它會嘗試擷取新建立的專案。
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
下列 C# 範例示範如何使用指定的路徑建立新的 DirectoryEntry 物件,然後在容器中建立新的專案並加以儲存。 它會嘗試擷取新建立的專案。
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);
}
}
}
下列 C++ 範例會使用指定的路徑建立新的 DirectoryEntry 物件,然後在容器中建立新的專案並加以儲存。 它會嘗試擷取新的專案。
#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);
}
}
備註
如果找不到相符的結果, DirectoryServicesCOMException 則會擲回錯誤碼0x2030。