Is there a .NET library for LDAP paths manipulations?
I would like to have something equivalent to System.IO.Path
, allowing e.g. to do something like
string ou1 = LDAPPath.Combine("OU=users","DC=x,DC=y");
string ou2 = LDAPPath.Parent("CN=someone,OU=users,DC=x,DC=y");
Otherwise, what's the common way to deal with LDAP distinguished names in .NET?
To clarify my question: I'm not asking about "directory services in .NET" in general; I've already worked with that and done some programs to perform some tasks. What I feel is missing is a proper way to manipulate paths, parse distinguished names and so on, and since this should be a pretty common need, I hope there's a cleaner way to do this than split a string on commas(1).
(1) like, for example, calling a function in a library that splits the string on commas
I use a couple of utility classes based off of the Win32 methods DsGetRdnW, DsQuoteRdnValueW, and DsUnquoteRdnValueW:
No, not to my knowledge - not even in the most recent .NET 3.5 namespace for Active Directory.
You can navigate the hierarchy (going to the parent etc.) in the directory itself - but you need to be bound to e.g. Active Directory by means of a
DirectoryEntry
.And then there's the
NameTranslate
API, but that's really more of a "change this name to another name", e.g. change from user-principal name to relative DN - and again, it requires a connection to aDirectoryEntry
in AD.I would be most interested in finding such a library, but so far, I haven't heard about one - neither in .NET nor in any other language, really.
Back in my "heavy-duty" AD programming days, I had my own set of LDAP path manipulation routines (in Delphi) - basically just string parsing and handling.
Marc
While there is no LDAP path parser in .NET, there is a URI parser. For those who need to simply parse "LDAP://domain/..." paths you can use the
System.Uri
class, then you can get some details like the following:If you use this DN parser you can also do the following instead to parse the path:
While I agree that .NET should have had this by now (shame!), this was at least an ok work around for my needs, though not perfect, and I doubt it will be robust enough for everyone.