Alexander
Alexander

Reputation: 20224

AD property is System.Byte[] - which Encoding to convert to string?

I am reading the displayName property from ActiveDirectory.

On Windows Server 2008, result.Properties["displayName"][0].ToString() is the displayName, while on Windows Server 2012, it returns System.Byte[]. Now I have to convert the value using sth like var buffer = result.Properties["displayName"][0]; Encoding.%SomeEncoding%.GetString(buffer, 0, buffer.Length);,
but I don't know which Encoding Microsoft chose - UTF, ISO, Default, Local?

By the way, is there a "cheat sheet" on AD properties and their types available?

Upvotes: 1

Views: 2762

Answers (2)

J Edward Banasik
J Edward Banasik

Reputation: 11

You can read a byte value from AD like this:

Encoding.UTF8.GetString((byte[])userRow.Properties["mailNickname"][0]);

Upvotes: 1

mtmk
mtmk

Reputation: 6316

Active Directory implements LDAP v3 and that uses UTF-8.

Upvotes: 2

Related Questions