Convert Distinguished Name to Canonical Name
active-directory, c#, directoryentry, directoryservices
Solution
It's a constructed attribute. On a DirectoryEntry, you need to use RefreshCache:
var de = new DirectoryEntry("CN=Murdock\, James,OU=Disabled Users,OU=GOG,DC=contoso,DC=local");
de.RefreshCache(new string[] {"canonicalName"});
Problem
Using `System.DirectoryServices` (i.e. the `DirectoryEntry` class) is there a way to convert the `DistinguishedName` attribute to, or get the Canonical Name that would normally appear in the Active Directory Users & Computers snap-in? I realize I could do this using regular expressions, but I would prefer a more reliable approach. For example, I want to convert this CN=Murdock\, James,OU=Disabled Users,OU=GOG,DC=contoso,DC=local to this contoso.local/GOG/Disabled Users/Murdock, James