Directory Services

DN with Binary Property Type

Properties such as distinguishedName and wellKnownObjects use the DN with binary property type. In ADSI, this property type is called ADSTYPE_DN_WITH_BINARY. This operation requires you to install COM Interop.

Note  In the Active Directory Schema, the syntax name for DN with binary is called Object(DN-Binary) and it is represented in the Syntax row of attribute tables with the Syntax ID of 2.5.5.7.

The following code example shows how to read a property that has a value that uses the DN with binary syntax.

[Visual Basic .NET]
Import ActiveDs
...
Dim wkObjects As [Object] = usr.Properties("wellKnownObjects").Value
Dim wkObject As DNWithBinary
For Each wkObject In  CType(wkObjects, IEnumerable)
	Dim bytes As Byte() = CType(wkObject.BinaryValue, Byte())
	Dim b As Byte
	For Each b In  bytes
		Console.Write("{0:x2}", b)
	Next b
	Console.WriteLine(wkObject.DNString)
 Next wkObject
[C#]
using ActiveDs;
...
Object wkObjects = ent.Properties["wellKnownObjects"].Value;
foreach(DNWithBinary wkObject in (IEnumerable) wkObjects)
{
	byte[] bytes= (byte[]) wkObject.BinaryValue;
	foreach(byte b in bytes)
	{
		Console.Write("{0:x2}",b);
}
	Console.WriteLine(wkObject.DNString);
}

The following code example shows how to write a property value that uses the DN with binary syntax.

[Visual Basic .NET]
Import ActiveDs
...
Dim dnBin As New ActiveDs.DNWithBinaryClass()
dnBin.DNString = usr.Properties("distinguishedName").Value.ToString()
dnBin.BinaryValue = usr.Guid.ToByteArray()
usr.Properties("singleDNWithBinary").Value = dnBin
usr.CommitChanges()
[C#]
using ActiveDs;
...
ActiveDs.DNWithBinary dnBin = new ActiveDs.DNWithBinaryClass();
dnBin.DNString = usr.Properties["distinguishedName"].Value.ToString();
dnBin.BinaryValue = usr.Guid.ToByteArray();
usr.Properties["singleDNWithBinary"].Value = dnBin;
usr.CommitChanges();