ExtendedDN usage?

I'm having a problem using the new ExtendedDN enum introduced in the 2.0 framework to return objectGUIDs as strings.  Previously, they were returned as octets, which had to be manually converted to a string.  The new ExtendedDN enum is to make life a little easier. :) I'm using .NET 2.0 beta 2.

Here's the MSDN info on ExtendedDN: http://msdn2.microsoft.com/library/ec42w73t(en-us,vs.80).aspx

string struser = "jdoe";
DirectorySearcher ds = new DirectorySearcher();
ds.Filter =
string.Format("samAccountName={0}", struser);
ds.PropertiesToLoad.Add(
"objectGuid");
ds.ExtendedDN =
ExtendedDN.Standard;

SearchResult sr = ds.FindOne();

if (sr != null)
{
Console.WriteLine("retrieved GUID: " + sr.Properties["objectGuid"][0].ToString());
}



Answer this question

ExtendedDN usage?

  • Nikhil Rajwade

    Hello jwaters,

    Can you clarify what issue you are encountering Are you not able to retrieve objectGUIDs as strings Is one of the lines in the sample code you provided not working as you expect Which line

    What are you seeing instead of the expected string in the array

    Thanks,
    Stephen
    http://blogs.msdn.com/stfisher

  • Will87

    You need to call the StringFromGuid method to get the Byte array convereted to a Guid. You don't get a Guid back but rather an array of bytes. See http://msdn2.microsoft.com/en-us/library/ms677985.aspx for more information.

  • Kha Tran

    Hi Stephen,

    My Console.Writeline outputs 'retrieved GUID: System.Byte[]'.  I was expecting to see 'retrieved GUID: 280A7B65-8F00-438F-989B-8EAF9E438A71'.

    Thanks,

    John

  • ExtendedDN usage?