简体   繁体   中英

DirectoryEntry Properties

I have a short quest for my C# project. I want to read out our active directory and use this:

System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry);

foreach (System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
{
        System.DirectoryServices.DirectoryEntry de = resEnt.GetDirectoryEntry();
        try
        {
            myRow["eMail"] = de.Properties["Mail"].Value.ToString();
        }
        catch (Exception)
        { }
}

Now I want to read out other Properties and hope that you can give me a List of all Properties.

Thanks

You can do it simply by below code

 DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry);

            foreach (System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
            {
                try
                {
                    foreach (string property in resEnt.Properties.PropertyNames)
                    {
                        string value = resEnt.Properties[property][0].ToString();

                        Console.WriteLine(property + ":" + value);
                    }
                }
                catch (Exception)
                { }
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM