c# using System.DirectoryServices.AccountManagement

G

golliz

Hi all!
I'm new to Active Directory and the interoperability with the framework.
I'm working with Active Directory and c# with the new framework 3.5 and the
System.DirectoryServices.AccountManagement library and PrincipalSearcher
class to search in the AD tree.
I must retrieve the "CanonicalName", DistinguishedName and SID.
I'm using this code:

public List<UserPrincipal> GetAllGroups(string uName, string pwd)
{
List<UserPrincipal> retVal = null;

//Create a context for the search take place in
using (PrincipalContext context = new PrincipalContext(ContextType.Domain
, "domainController", "OU=*****,OU=****,DC=****,DC=****"
, ContextOptions.Negotiate, uName, pwd))
{
//Create a group principal filter with the context
using (UserPrincipal filter = new UserPrincipal(context))
{
//Create a principal search using the filter
using (PrincipalSearcher searcher = new PrincipalSearcher())
{
retVal = (from principal in searcher.FindAll()
select principal as UserPrincipal).ToList();

foreach (UserPrincipal user in retVal) {

System.Security.Principal.SecurityIdentifier sid
= user.Sid;
string soj = user.StructuralObjectClass;
string upn = user.UserPrincipalName;
string name = user.Name;
string dsn = user.DistinguishedName;
}
}
}
}

return retVal;
}
It's all ok for DistinguishedName and SID but I Can't find the Attribute
"CanonicalName" in my UsersPrincipal and I dont know how can i resolve it.
Any help is welcome.
Thanks so mutch bye.
 
G

golliz

golliz said:
Hi all!
I'm new to Active Directory and the interoperability with the framework.
I'm working with Active Directory and c# with the new framework 3.5 and the
System.DirectoryServices.AccountManagement library and PrincipalSearcher
class to search in the AD tree.
I must retrieve the "CanonicalName", DistinguishedName and SID.
I'm using this code:

public List<UserPrincipal> GetAllGroups(string uName, string pwd)
{
List<UserPrincipal> retVal = null;

//Create a context for the search take place in
using (PrincipalContext context = new PrincipalContext(ContextType.Domain
, "domainController", "OU=*****,OU=****,DC=****,DC=****"
, ContextOptions.Negotiate, uName, pwd))
{
//Create a group principal filter with the context
using (UserPrincipal filter = new UserPrincipal(context))
{
//Create a principal search using the filter
using (PrincipalSearcher searcher = new PrincipalSearcher())
{
retVal = (from principal in searcher.FindAll()
select principal as UserPrincipal).ToList();

foreach (UserPrincipal user in retVal) {

System.Security.Principal.SecurityIdentifier sid
= user.Sid;
string soj = user.StructuralObjectClass;
string upn = user.UserPrincipalName;
string name = user.Name;
string dsn = user.DistinguishedName;
}
}
}
}

return retVal;
}
It's all ok for DistinguishedName and SID but I Can't find the Attribute
"CanonicalName" in my UsersPrincipal and I dont know how can i resolve it.
Any help is welcome.
Thanks so mutch bye.

noone can Help?
 
M

Marc Scheuner

I must retrieve the "CanonicalName", DistinguishedName and SID.
It's all ok for DistinguishedName and SID but I Can't find the Attribute
"CanonicalName" in my UsersPrincipal and I dont know how can i resolve it.

"CanonicalName" is the "full length" name for the "cn" attribute.

Marc
 
G

golliz

"CanonicalName" is the "full length" name for the "cn" attribute.

Hi Marc and thanks for your help.
I can't find property "CanonicalName" as a UserPrincipal Attribute.
So I solved the question formatting the "DistinguishedName" as the
"CanonicalName".
bye Mick
 
Top