<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>General</title><link>https://www.infopathdev.com:443/forums/41.aspx</link><description>If you're not sure where to ask your question, ask it here. If necessary, our moderators will make sure it gets classified in the correct board.</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>Populate dropdowns with domain names from ADS</title><link>https://www.infopathdev.com:443/forums/thread/4697.aspx</link><pubDate>Tue, 07 Jun 2005 12:22:46 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:4697</guid><dc:creator>AK721751</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/4697.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=41&amp;PostID=4697</wfw:commentRss><description>In my Infopath form,I need to populate a dropdown with the names of the domains from the Active Directory Services.&lt;br /&gt;&lt;br /&gt;The DirectorySearcher class and the FindAll() method helps us to get the list of the domains in the ADS server where I am running this webservice.&lt;br /&gt;&lt;br /&gt;Is it possible to obtain the list of domains from a remote ADS server.&lt;br /&gt;&lt;br /&gt;If so can u suggest a solution.&lt;br /&gt;&lt;br /&gt;The code which I am currently using requires me to run the webservices in a machine which is the ADS server.&lt;br /&gt;The code is as follows...&lt;br /&gt;&lt;br /&gt;public XmlNode GetListOfDomains()&lt;br /&gt;		{&lt;br /&gt;			DataSet dsDomain = new DataSet(); &lt;br /&gt;			DataSet dsForest=new DataSet();&lt;br /&gt;			dsForest.ReadXml("d:\\forests.xml");&lt;br /&gt;			Hashtable hstDomains=new Hashtable();&lt;br /&gt;			try&lt;br /&gt;&lt;br /&gt;			{&lt;br /&gt;				//Get list of Forest entires from Application object.&lt;br /&gt;				 &lt;br /&gt;				Hashtable hstForest = StartRead("d:\\forests.xml");//This XML file contains the domain name.&lt;br /&gt;				Hashtable hstDomainPath=new Hashtable();&lt;br /&gt;				//string strADSPath="";&lt;br /&gt;				foreach(string key in hstForest.Keys)&lt;br /&gt;				{&lt;br /&gt;					try&lt;br /&gt;					{&lt;br /&gt;						//Create an instance of Directory entry for the given forest.&lt;br /&gt;						DirectoryEntry deADS=new DirectoryEntry(key);&lt;br /&gt;						//create an instance of DirectorySearcher for the directory entry&lt;br /&gt;						DirectorySearcher dirSrchADS=new DirectorySearcher(deADS);&lt;br /&gt;						//Assign LDAP filter to DirectorySearcher to find only Domain objects&lt;br /&gt;						dirSrchADS.Filter="(objectCategory=domainDNS)";&lt;br /&gt;						//Load only the "name" property of directory searcher&lt;br /&gt;						dirSrchADS.PropertiesToLoad.Add("name");&lt;br /&gt;						//loop thru the directorysearcher for all the possible findings&lt;br /&gt;						foreach(SearchResult result in dirSrchADS.FindAll())&lt;br /&gt;						{&lt;br /&gt;							//create an instance of DirectoryEntry from the searchresult object&lt;br /&gt;							DirectoryEntry deDomains = result.GetDirectoryEntry();&lt;br /&gt;							//hstDomains.Add(((object)deDomains.Properties["name"].Value).ToString(),((object)deDomains.Properties["name"].Value).ToString());&lt;br /&gt;							//There could be more than one Domains in the same name, so add all the domains with same name in a hashtable&lt;br /&gt;							if(!hstDomains.ContainsKey(deDomains.Properties["name"].Value.ToString()))&lt;br /&gt;								hstDomainPath =new Hashtable();&lt;br /&gt;							hstDomainPath.Add(deDomains.Path.ToString(),hstForest[key].ToString());&lt;br /&gt;							//Add the hstDomainPath hashtable into hstDomains hashtable.&lt;br /&gt;							hstDomains.Add(((object)deDomains.Properties["name"].Value).ToString(),hstDomainPath);&lt;br /&gt;						}&lt;br /&gt;						//if no domains are found nullify the hstDomains hashtable&lt;br /&gt;						if(hstDomains.Count==0)&lt;br /&gt;							hstDomains=null;&lt;br /&gt;					}&lt;br /&gt;					catch(Exception	ex)&lt;br /&gt;					{&lt;br /&gt;						throw ex;&lt;br /&gt;					}&lt;br /&gt;				}&lt;br /&gt;			}&lt;br /&gt;			catch(Exception ex)&lt;br /&gt;			{&lt;br /&gt;				throw ex;&lt;br /&gt;			}&lt;br /&gt;			XmlDataDocument dom = new XmlDataDocument(dsForest );&lt;br /&gt;			return dom.DocumentElement;&lt;br /&gt;		}&lt;br /&gt;</description></item></channel></rss>