I have a
big problemwith the integration of
ActiveDirectory invisual studio2010 withc#language. I have to createtemplates
ofbusiness, with fields
thatare compiledautomaticallyby queryingthe
active directory(LDAP) anyone has someworking code, orgood ideasplease?
Thanks for the code. Can Iask you to
putin order, soI can
copy it andpaste it intoa projectin visualstudio 2010
C#? I am notvery practical
forthis language andI have troubleorganizing it.
nick251988
Member
4 Points
48 Posts
Displaying Active Directory fields on a web form c#
Jul 30, 2012 12:31 PM|LINK
I have a big problem with the integration of Active Directory in visual studio 2010 with c # language.
I have to create templates of business, with fields that are compiled automatically by querying the active directory (LDAP)
anyone has some working code, or good ideas please?
shabirhakim1
Star
13504 Points
2149 Posts
Re: Displaying Active Directory fields on a web form c#
Jul 30, 2012 01:20 PM|LINK
You need to set refrence to System.DirectoryServices.Actually i was getting problem with forum editor.Today it is fine
private string GetActiveDirUserDetails(string userid) { System.DirectoryServices.DirectoryEntry dirEntry = default(System.DirectoryServices.DirectoryEntry); System.DirectoryServices.DirectorySearcher dirSearcher = default(System.DirectoryServices.DirectorySearcher); string domainName = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName; try { dirEntry = new System.DirectoryServices.DirectoryEntry("LDAP://" + domainName); dirSearcher = new System.DirectoryServices.DirectorySearcher(dirEntry); dirSearcher.Filter = "(samAccountName=" + userid + ")"; dirSearcher.PropertiesToLoad.Add("GivenName"); //Users e-mail address dirSearcher.PropertiesToLoad.Add("sn"); //Users last name SearchResult sr = dirSearcher.FindOne(); //return false if user isn't found if (sr == null) { return false; } System.DirectoryServices.DirectoryEntry de = sr.GetDirectoryEntry(); dynamic userFirstLastName = de.Properties("sn").Value.ToString() + ", " + de.Properties("GivenName").Value.ToString(); return userFirstLastName; // return false if exception occurs } catch (Exception ex) { return ex.Message; } }nick251988
Member
4 Points
48 Posts
Re: Displaying Active Directory fields on a web form c#
Jul 31, 2012 08:26 AM|LINK
Thanks for the code.
Can I ask you to put in order, so I can copy it and paste it into a project in visual studio 2010 C #?
I am not very practical for this language and I have trouble organizing it.
Thanks again for the help.