Retrieve additional attributes

Dec 23, 2008 at 7:46 PM

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,


Dec 30, 2008 at 2:18 PM

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;

            PropertyCollection coll = entry.Properties;

            object obVal = coll[prop].Value;

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

        catch (Exception ex)

        return retVal;

here is a link to all the available User Object Attributes