Last post Oct 24, 2011 11:56 AM by bokbob
Oct 12, 2011 06:28 PM|bokbob|LINK
Hi, i am trying to get the 'physicalDeliveryOfficeName' from DirectoryEntry object...
could you please let me know how to view that value on that field ..
Oct 13, 2011 12:21 AM|kushal.dwivedi|LINK
Here is a sample on how you can get it from a directorytEntry object.
strDN="cn=user1,cn=users,dc=domainname,dc=com"; // DistinguishedName of a user
DirectoryEntry de = new
string str = de.Properties["physicalDeliveryOfficeName"].Value;
Oct 13, 2011 11:00 AM|bokbob|LINK
Hi i have bit of confusion on how to get strDN out of directory entry..
this is what i was doing before...could you please let me know how to forma a line to get strDN ?
de = new
Oct 14, 2011 01:27 AM|kushal.dwivedi|LINK
You will not get strDN (Distinguishedname value) from WinNT provider. you have to use LDAp provider and bind to Active Directory to get this value.
If you have a LDAP browser, you can navigate to the desired object and get the distinguishedName property value from there.
I have written a piece of code to get this value for you to get it dynamically.
string strDN = string.Empty;
using (DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE" ))
string dnc = rootDSE.Properties["DefaultNamingContext"].Value.ToString();
using(DirectoryEntry root = new DirectoryEntry("LDAP://" + dnc))
using (DirectorySearcher searcher = new DirectorySearcher(root))
searcher.Filter = "(&(ObjectCategory=person)(objectClass=User)(samAccountName=" + Environment.UserName + "))";
searcher.SearchScope = SearchScope.Subtree;
SearchResult searchResult = searcher.FindOne();
strDN = searchResult.Properties["distinguishedName"].ToString();
Hope it helps!
Oct 24, 2011 11:56 AM|bokbob|LINK
Hi can i do this in Global.asax and access the result variable where ever i need it ?
if yes, please let me know how to declare public variables in global.asax files and how to access them ?