Directory Programming .NET

Active Directory and ADAM programming support for .NET developers
Welcome to Directory Programming .NET Sign in | Join | Help
in Search

How to convert objectguid to string

Last post 03-11-2010, 12:15 PM by kajalmalik. 3 replies.
Sort Posts: Previous Next
  •  03-11-2010, 1:17 AM 7943

    How to convert objectguid to string

    Hi,

    I have a c## application that queries the AD and loads objectGuid as one of the properties. I would like to populate the data returned from active directory in a table [oracle database] with object guid as a key.

    Couple of things I would like to know:

    - what is the best datatype going to be of this field (storing objectGuid) value in oracle table?

    - how do I retrieve the string value from objectguid?

    As of now I am using following code to display samaccountname would like something in similar lines:

    var mySearcher = new DirectorySearcher(directoryEntry)

    mySearcher.PropertiesToLoad.Add("samAccountName");

    mySearcher.PropertiesToLoad.Add("objectGUID");

    var resultCollection = mySearcher.FindAll();

    foreach (System.DirectoryServices.SearchResult resEnt in resultCollection)

    {

       sw1.WriteLine(String.Format("{0}", resEnt.Properties["samaccountname"][0].ToString()));

    }

     

    Thanks

    Kajal

  •  03-11-2010, 8:58 AM 7944 in reply to 7943

    Re: How to convert objectguid to string

    Hi.

    I'm currently doing something like that.

    We store the objectGUID as a string in the data base, and so far, it's worked fine for us.

    To convert the objectGUID to string we could do it like this:

    returnValue.UserKey = new Guid((byte[])_result.Properties["objectguid"][0]).ToString();

    since the objectGUID must be only one, if I am not mistaken.

    Regards
  •  03-11-2010, 10:21 AM 7945 in reply to 7944

    Re: How to convert objectguid to string

    The best method is to cast the objectGUID attribute returned to a byte[] and pass that to the constructor on the Guid struct. Then, call one of its ToString overrides. This is exactly what the sample above shows. :)

    There are also samples from ch 3 of the book in the downloads section.

  •  03-11-2010, 12:15 PM 7947 in reply to 7945

    Re: How to convert objectguid to string

    Thanks so much Casiel & Joe. I was looking for something like this only.
View as RSS news feed in XML