How to get the Properties an object supports lets say ObjectClass=Group

Last post 03-27-2008 11:43 AM by stanlj10. 8 replies.

Sort Posts:

  • How to get the Properties an object supports lets say ObjectClass=Group

    03-13-2008, 2:39 AM
    • Member
      5 point Member
    • samridhis
    • Member since 10-04-2003, 3:14 PM
    • India
    • Posts 13

    Hi,

     

              I have to search for Groups in Active directory. But while coding I have to add the properties I have to fetch using the code DirectorySearcher.PropertiesToLoad.Add("");

         So, I need help from where I can get the properties which a Group type supports. So that I can complete my code.

     

    Thanks & Regards,

     

    Sam

    Samridhi Shukla
    Asp.net Developer
  • Re: How to get the Properties an object supports lets say ObjectClass=Group

    03-13-2008, 3:58 AM
    • All-Star
      22,266 point All-Star
    • vik20000in
    • Member since 12-30-2005, 6:02 AM
    • Kolkata
    • Posts 3,464
    Type objType = obj.GetType(); //Chnage this to the object u want
          PropertyInfo[] objPropertiesArray =
                  objType.GetProperties();

          foreach (PropertyInfo objProperty in objPropertiesArray) {

             Control control =
                         container.FindControl(objProperty.Name);
             if (control != null) {
                 // process Control ...
             }
          }

     

    Vikram
    www.vikramlakhotia.com


    Please mark the answer if it helped you
  • Re: How to get the Properties an object supports lets say ObjectClass=Group

    03-13-2008, 5:07 AM
    • Member
      5 point Member
    • samridhis
    • Member since 10-04-2003, 3:14 PM
    • India
    • Posts 13

    Actually the System.DirectoryServices.DirectorySearcher object returns the SearcherResult Object. This object will load properties of object based up the properties i have added using the method name DirectorySearcher.PropertiesToLoad.Add(""); But i don't know which properties to load. Do you have any idea about loading the properties for users.

    Samridhi Shukla
    Asp.net Developer
  • Re: How to get the Properties an object supports lets say ObjectClass=Group

    03-24-2008, 5:44 PM
    • Member
      4 point Member
    • stanlj10
    • Member since 03-24-2008, 5:39 PM
    • Posts 2
    Here is only way i know how, but for me, it is only returning properties that are populated so i am missing properties.  Anyone got a fix for my problem?

    DirectoryEntry directoryEntry = new DirectoryEntry("LDAP://" + "server.com");

    DirectorySearcher directorySearcher = new DirectorySearcher(directoryEntry);directorySearcher.Filter = "(&(objectClass=" + "Group" + "))";

     

    SearchResult searchResult = directorySearcher.FindOne();

    DirectoryEntry dEntry = searchResult.GetDirectoryEntry();

    string result = string.Empty;

    foreach (string propertyName in searchResult.Properties.PropertyNames)

    {

    mPublicProperties.Add(propertyName, dEntry.Properties[propertyName].Value);

    }

  • Re: How to get the Properties an object supports lets say ObjectClass=Group

    03-26-2008, 6:25 PM
    • All-Star
      28,218 point All-Star
    • johram
    • Member since 06-13-2006, 10:36 AM
    • Sweden
    • Posts 3,543
    • Moderator

    To get a list of all possible attributes for an object class, you should query the schema. If you just want a list of the attributes (in human readable format), see this link. If you use Adsiedit then you'll notice that it lists all possible attributes for a class when you edit it. That information is stored only in the schema.

    An object (instance) only contains the attributes that are actually populated. So if look in the Properties collection for an object, you won't find for example telephoneNumber unless it has a value - even if it's in the schema for that object.

    If this post was useful to you, please mark it as answer. Thank you!
  • Re: How to get the Properties an object supports lets say ObjectClass=Group

    03-27-2008, 1:11 AM
    Answer
    • Member
      5 point Member
    • samridhis
    • Member since 10-04-2003, 3:14 PM
    • India
    • Posts 13

    Hi Team,

     

             Thanks for your answers. I did some research and found out that. We can get the properties through schema which is defined in hirarchical manner through inheritence.

            If we use the ADSI Edit Tool  and select an object. This tool display all the properties for that object.

     

    Thanks & Regards,

     

    Samridhi Shukla

    Samridhi Shukla
    Asp.net Developer
  • Re: How to get the Properties an object supports lets say ObjectClass=Group

    03-27-2008, 1:14 AM
    Answer
    • Member
      5 point Member
    • samridhis
    • Member since 10-04-2003, 3:14 PM
    • India
    • Posts 13

    We can also get the properties by using the below code. This code is provided in wrox professional 2nd edition Active Directory folder.

     

    public static void ShowUserObject()

    {

    using (DirectoryEntry de = new DirectoryEntry())

    {

    de.Path = "LDAP://celticrain/CN=Christian Nagel, OU=Wrox Press, " +

    "DC=eichkogelstrasse, DC=local";

    Console.WriteLine("Name: " + de.Name);

    Console.WriteLine("GUID: " + de.Guid);

    Console.WriteLine("Type: " + de.SchemaClassName);

    Console.WriteLine();

    Console.WriteLine("Properties: ");

    PropertyCollection properties = de.Properties;

     

    foreach (string name in properties.PropertyNames)

    {

    foreach (object o in properties[name])

    {

    Console.WriteLine(name + ": " + o);

    }

    }

    }

    }

    Samridhi Shukla
    Asp.net Developer
  • Re: How to get the Properties an object supports lets say ObjectClass=Group

    03-27-2008, 6:11 AM
    • All-Star
      28,218 point All-Star
    • johram
    • Member since 06-13-2006, 10:36 AM
    • Sweden
    • Posts 3,543
    • Moderator

     Please mark this thread as answered as it will help others looking for a solution to the same problem. Thanks.

    If this post was useful to you, please mark it as answer. Thank you!
  • Re: How to get the Properties an object supports lets say ObjectClass=Group

    03-27-2008, 11:43 AM
    • Member
      4 point Member
    • stanlj10
    • Member since 03-24-2008, 5:39 PM
    • Posts 2

    Using properties.PropertyNames as shown in an example above, only gets u properties that are populated on that specific ObjectClass.  In the example above, if CN=Christian Nagel doesn't have a telephone number, you won't get the TelephoneNumber property.  Best way i found was to use "allowedAttributes" attribute.  Google it and u will find a good example.  Using the DirectoryServices.ActiveDirectorySchema works too, but i think that limits to AD only.

Page 1 of 1 (9 items)