madhukar_konda
asked on
How to get windows domain list in a combo box (asp.net)
Hi All,
Does any one know how to get the list of all available windows domains (domain list) into a combo box? Similar to the combo box that we get while logging into windows.
Thanks
Konda
Does any one know how to get the list of all available windows domains (domain list) into a combo box? Similar to the combo box that we get while logging into windows.
Thanks
Konda
Hello
Try this code
private void button1_Click(object sender, System.EventArgs e)
{
StringCollection adDomains = this.GetDomainList();
foreach (string strDomain in adDomains)
{
comboBox1.Items.Add(strDom ain);
}
}
private StringCollection GetDomainList()
{
StringCollection domainList = new StringCollection();
try
{
DirectoryEntry en = new DirectoryEntry("LDAP://");
// Search for objectCategory type "Domain"
DirectorySearcher srch = new DirectorySearcher("objectC ategory=Do main");
SearchResultCollection coll = srch.FindAll();
// Enumerate over each returned domain.
foreach (SearchResult rs in coll)
{
ResultPropertyCollection resultPropColl = rs.Properties;
foreach( object domainName in resultPropColl["name"])
{
domainList.Add(domainName. ToString() );
}
}
}
catch (Exception ex)
{
MessageBox.Show (ex.Message);
}
return domainList;
}
HTH
Regards,
Mohammed
Try this code
private void button1_Click(object sender, System.EventArgs e)
{
StringCollection adDomains = this.GetDomainList();
foreach (string strDomain in adDomains)
{
comboBox1.Items.Add(strDom
}
}
private StringCollection GetDomainList()
{
StringCollection domainList = new StringCollection();
try
{
DirectoryEntry en = new DirectoryEntry("LDAP://");
// Search for objectCategory type "Domain"
DirectorySearcher srch = new DirectorySearcher("objectC
SearchResultCollection coll = srch.FindAll();
// Enumerate over each returned domain.
foreach (SearchResult rs in coll)
{
ResultPropertyCollection resultPropColl = rs.Properties;
foreach( object domainName in resultPropColl["name"])
{
domainList.Add(domainName.
}
}
}
catch (Exception ex)
{
MessageBox.Show (ex.Message);
}
return domainList;
}
HTH
Regards,
Mohammed
ASKER
Hi Mohammed.
Thanks for your reply. But it is giving me only one domain to which i logged in. any ideas?
I want all the available domains in the network. Similar to windows login screen domain list.
Thanks for your reply. But it is giving me only one domain to which i logged in. any ideas?
I want all the available domains in the network. Similar to windows login screen domain list.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Mohammed!
It does work. I really appriciate your quick response.
It does work. I really appriciate your quick response.
Glad to help you :-)
ASKER
Public Function EnumerateDomains() As ArrayList
Dim arrayDomains As New ArrayList
Try
Dim queryString As String = "Select domain From Win32_ComputerSystem"
Dim searchDomains As New Management.ManagementObjec
For Each domainCurrent As Management.ManagementBaseO
arrayDomains.Add(domainCur
Next domainCurrent
Catch ex As Exception
MessageBox.Show(ex.ToStrin
End Try
Return arrayDomains
End Function 'EnumerateDomains'
But, this function is returning currently user logged in domain. I want all the existing domains. Any ideas??