Re: casting type for objectGuid

dl
Date: 05/28/05


Date: Sat, 28 May 2005 18:47:05 +0800

Hi Joe
The problem with datatable is whenever I try to assign with the following
statement I get a casting error
dr[i] = (string)resEnt.Properties["objectGuid"][0];

I saw an example that can write NativeGuid directly from the returned
directoryentry, as below, does it mean I instantiate another directoryEntry
instance and simply assign this NativeGuid to a string variable?

TIA

String myADSPath =
"LDAP://onecity/CN=Users,DC=onecity,DC=corp,DC=fabrikam,DC=com";
DirectoryEntry myDirectoryEntry=new
DirectoryEntry(myADSPath,UserName,SecurelyStoredPassword);

// Display the Guid and NativeGuid.
Console.WriteLine("The GUID of the ADS object:"+
                  myDirectoryEntry.Guid);
Console.WriteLine("The Native GUID of the ADS"+
                  "object:"+myDirectoryEntry.NativeGuid);

"Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com> wrote
in message news:ubyIYssYFHA.980@TK2MSFTNGP12.phx.gbl...
> In AD/S.DS, objectGUID is returned from a DirectoryEntry or SearchResult
as
> a byte array. You would want to cast that to a byte array, then pass that
> byte array to the constructor on a Guid structure. That will give you a
> valid .NET Guid.
>
> I can't remember the exact syntax to pass it into SQL to get it set up as
a
> UniqueIdentifier column (which is the correct SQL type for a GUID), but as
I
> recall, you pass it in your query as a String. Call the ToString method
on
> the Guid to get this.
>
> HTH,
>
> Joe K.
>
> <dl> wrote in message news:Olh5aApYFHA.3220@TK2MSFTNGP14.phx.gbl...
> > Hi
> > I am trying to put a user's objectGuid as the primary key onto a
datatable
> > and be used as the unique key on editing / updating. But I seem to get
> > casting error with the following statement
> > dt.Columns.Add(new DataColumn("object_Guid", typeof(string)));
> >
> > Any idea?
> >
> > TIA
> >
> > --
> >
> >
> >
>
>



Relevant Pages

  • Re: casting type for objectGuid
    ... I'd suggest not using the NativeGuid property for this. ... confuse SQL server which is likely to expect it in string format. ... You can use the Guid property if you want though. ... DirectoryEntry and SearchResult objects. ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Binding DirectoryEntry to AD object via GUID
    ... Binding via the GUID is covered here in the docs: ... you can use either the Guid property or the NativeGuid property ... NativeGuid returns a string that contains the same Guid in octet string ... DirectoryEntry or a SearchResult), you can cast that to a byteand pass ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Binding DirectoryEntry to AD object via GUID
    ... you can use either the Guid property or the NativeGuid property ... > to create the binding string. ... >> DirectoryEntry constructors do not seem to take Guid's nor can you set the ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • RE: ReplacementStrings on EventLog entries Messages
    ... As I understand, you want to log some messages in eventlog, but I am not ... very clear about %{SID} and %{GUID} you mentioned. ... GUID or NativeGuid are ...
    (microsoft.public.dotnet.languages.csharp)