locked
Snippet to obtain Active Directory Path RRS feed

  • Question

  • User-563238995 posted

    Sumply return the path of AD when executed on a domain.

    public string ActiveDirectoryPath()
    {
    	DirectoryEntry root = new DirectoryEntry("LDAP://RootDSE");
    	using (root)
    	{
    		string dnc = root.Properties["defaultNamingContext"][0].ToString();
    		string server = root.Properties["dnsHostName"][0].ToString();
    		string adsPath = String.Format("LDAP://{0}/{1}", server, dnc);
    		return adsPath;
    	}
    }
     
    Saturday, June 13, 2009 10:47 PM

All replies