Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Per enumerare gli oggetti in un contenitore, creare un oggetto DirectoryEntry che sia utilizzabile per gestire ogni oggetto e le relative proprietà. Sarà quindi possibile utilizzare le proprietà fornite dall'oggetto DirectoryEntry per recuperare dati come l'attributo del nome. È possibile scorrere tutti gli oggetti nel contenitore utilizzando l'istruzione Using foreach with Arrays.
Nell'esempio di codice riportato di seguito viene illustrato come enumerare un contenitore di utenti.
Try
' Bind to the container to enumerate.
Dim ent As New DirectoryEntry("LDAP://CN=users,OU=Marketing,DC=fabrikam,DC=com")
' Create an object to use for individual objects in the container and iterate
' through the container.
Dim child As DirectoryEntry
For Each child In ent.Children
' Write the name and path for each object in the container.
Console.WriteLine("{0} {1}", child.Name, child.Path)
Next child
Catch Exception1 As Exception
' Handle errors.
End Try
try
{
// Bind to the container to enumerate.
DirectoryEntry ent = new DirectoryEntry("LDAP://CN=users,OU=Marketing,DC=fabrikam,DC=com");
// Create an object to use for individual objects in the container and iterate
// through the container.
foreach( DirectoryEntry child in ent.Children)
{
// Write the name and path for each object in the container.
Console.WriteLine( "{0} {1}", child.Name, child.Path);
}
}
catch
{
// Handle errors.
}
Vedere anche
Riferimenti
System.DirectoryServices
DirectoryEntry
Concetti
Send comments about this topic to Microsoft.
Copyright © 2007 Microsoft Corporation. Tutti i diritti riservati.