Binding DirectoryEntry to AD object via GUID

G

Gary K

I notice in the help files a reference that implies that you can create a
DirectoryEntry object that binds directly to an active directory object vai
it's GUID. The properties where I found this reference are the Guid and
NativeGuid properties. I cannot locate where or how to do this, the
DirectoryEntry constructors do not seem to take Guid's nor can you set the
NativeGuid, so how can I do this? Is it even possible? I'm asking because I
want to store a link to a user's account infomration in a SQL database so
that supervisors can manipulate user accounts without browsing the AD tree.
Thanks
 
J

Joe Kaplan \(MVP - ADSI\)

Binding via the GUID is covered here in the docs:

http://msdn.microsoft.com/library/d.../en-us/dnanchor/html/networkdirectoryserv.asp

The examples are for ADSI, but they apply equally well to S.DS.

Essentially, you can use either the Guid property or the NativeGuid property
to create the binding string. Guid returns a .NET Guid object and
NativeGuid returns a string that contains the same Guid in octet string
format. ADSI accepts either the octet string format or the
Guid.ToString("D").

So to create the binding string, you would do either:
String.Format("LDAP://<{0}>", entry.NativeGuid)
or
String.Format("LDAP://<{0}>", entry.Guid.ToString("D"))

Also, if you get the objectGuid property directly (from either the
DirectoryEntry or a SearchResult), you can cast that to a byte[] and pass
that to the Guid constructor to use the second format above.

Normally, all the S.DS questions are fielded in the adsi.general newsgroup.

HTH,

Joe K.
 
G

Gary K

Thanks for that, sorry about the mispost.

Joe Kaplan (MVP - ADSI) said:
Binding via the GUID is covered here in the docs:

http://msdn.microsoft.com/library/d.../en-us/dnanchor/html/networkdirectoryserv.asp

The examples are for ADSI, but they apply equally well to S.DS.

Essentially, you can use either the Guid property or the NativeGuid property
to create the binding string. Guid returns a .NET Guid object and
NativeGuid returns a string that contains the same Guid in octet string
format. ADSI accepts either the octet string format or the
Guid.ToString("D").

So to create the binding string, you would do either:
String.Format("LDAP://<{0}>", entry.NativeGuid)
or
String.Format("LDAP://<{0}>", entry.Guid.ToString("D"))

Also, if you get the objectGuid property directly (from either the
DirectoryEntry or a SearchResult), you can cast that to a byte[] and pass
that to the Guid constructor to use the second format above.

Normally, all the S.DS questions are fielded in the adsi.general newsgroup.

HTH,

Joe K.

Gary K said:
I notice in the help files a reference that implies that you can create a
DirectoryEntry object that binds directly to an active directory object vai
it's GUID. The properties where I found this reference are the Guid and
NativeGuid properties. I cannot locate where or how to do this, the
DirectoryEntry constructors do not seem to take Guid's nor can you set the
NativeGuid, so how can I do this? Is it even possible? I'm asking because I
want to store a link to a user's account infomration in a SQL database so
that supervisors can manipulate user accounts without browsing the AD tree.
Thanks
 
J

Joe Kaplan \(MVP - ADSI\)

No need to apologize. It is pretty unobvious where to post S.DS questions
unless you already know :) MS has so far rejected my requests for an S.DS
newsgroup which would help with this. I was just trying to spread the word
in case you had follow ups.

Joe K.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top