I have a reference to a user object, the Properties collection of this object will only contain properties that have values set but I need to check if a property (by name) exists for this object - I guess this would come from the schema. I have looked at deUser.SchemaEntry , but I can't find any useful property info from this object. Any ideas?
DirectoryEntry deUser = new DirectoryEntry(path); foreach (var prop in deUser.Properties) < //if user.Properties["company"] is not set on this user then //it will not be available here although 'company' is //a property defined for the user class >//How do I get to the list of all available properties using //deUserSchema as below DirectoryEntry deUserSchema = deUser.SchemaEntry();
2,753 8 8 gold badges 43 43 silver badges 69 69 bronze badges
asked Aug 20, 2015 at 10:59
1,146 3 3 gold badges 11 11 silver badges 28 28 bronze badges
could you post the code you describe in your question.
Commented Aug 20, 2015 at 11:03
The problem turned out to be easier to solve than it appeared. In each object (DirectoryEntry) in AD there are dynamic properties named allowedAttributes and allowedAttributesEffective .
On standard retrieval by de.Attributes [], returns null . You must first force the rebuild of the object cache ( de.RefreshCache ) with these parameters. My code:
public static List AllAvailableProperties(this DirectoryEntry de) < de.RefreshCache(new string[] < "allowedAttributes" >); return de.Properties["allowedAttributes"].AsStringList(); >
If we want a list of attributes for a class, we should take any object (existing) of this class.
5,152 2 2 gold badges 50 50 silver badges 73 73 bronze badges answered May 6, 2021 at 11:39 Tommy Malicki Tommy Malicki 31 4 4 bronze badgesTo list all properties try this :
foreach (var name in deUser.Properties.PropertyNames)answered Aug 20, 2015 at 13:09 526 2 2 silver badges 12 12 bronze badges That will return only property names that have values set but not the others - that's my problem Commented Aug 20, 2015 at 15:29
According to MSDN you can use DirectoryEntry.SchemaEntry to retrieve all attributes.
An entry's schema determines a list of its mandatory and optional property names. You can use this property to find out what properties and methods are available on the associated object.
String myADSPath = "LDAP://onecity/CN=Users,DC=onecity,DC=corp,DC=fabrikam,DC=com"; // Creates an Instance of DirectoryEntry. DirectoryEntry myDirectoryEntry=new DirectoryEntry(myADSPath, UserName, SecurelyStoredPassword); // Gets the SchemaEntry of the ADS object. DirectoryEntry mySchemaEntry = myDirectoryEntry.SchemaEntry; if (string.Compare(mySchemaEntry.Name,"container") == 0) < foreach(DirectoryEntry myChildDirectoryEntry in myDirectoryEntry.Children) < //. do what you need >>