Retrieve additional attributes

Dec 23, 2008 at 8:46 PM
Hello,

I noticed this section of code

            // We're not retrieving any additional attributes
            //string[] attributes = new string[] { "sAMaccountName" };
            //initInfo.cAttributesToFetch = (uint)attributes.Length;
            //initInfo.apwzAttributeNames = Marshal.StringToHGlobalUni( attributes[0] );

I tried to uncomment this section of code, but I get a NotImplemented Exception back from this line

            dataObj.GetData(ref fe, ref stg);

Any Thoughts?

Thanks for the help,

Andrew





Dec 30, 2008 at 3:18 PM
Hello,

I actually figured this out, and it's very simple in c#

In the ProcessSelections(IDataObject dataObj) method, when you retrieve the adsPath from each selected AD object, just construct a DirectoryEntry object, and parse the Properties collection to get additional attributes.

string name = s.pwzName;
string path = s.pwzADsPath;
string schemaClassName = s.pwzClass;
string upn =  s.pwzUPN;
selections[i] = new DirectoryObject( name, path, schemaClassName, upn );

DirectoryEntry entry = new DirectoryEntry(path);
string description = GetObjectProperty(entry, "Description");

private string GetObjectProperty(DirectoryEntry entry, string prop)
{
        string retVal = string.Empty;

        try
        {
            PropertyCollection coll = entry.Properties;

            object obVal = coll[prop].Value;

            if (obVal != null)
           {
                    retVal = obVal.ToString();
           }

        }
        catch (Exception ex)
        {
             MessageBox.Show(ex.Message);
        }

        return retVal;
}

here is a link to all the available User Object Attributes