ahussain
08-14-2007, 08:14 AM
Hello,
I have successfully connected to Active directory using asp.net c#
But problem is I want to display all the users and there attribute in my datagrid i.e user login name,emai, department,title etc . Please correct me where I am doing mistake. Thanks in advance....
string dom = "MyDomain";
DirectoryEntry entry = new DirectoryEntry("LDAP://" + dom);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = ("(objectClass=user)");
foreach(SearchResult resEnt in mySearcher.FindAll())
{
try
{
DirectoryEntry de=resEnt.GetDirectoryEntry();
'adding bound columns to the datagrid
BoundCoulmn dataGridCol = new BoundCoulmn();
datagridcol.HeaderText = "User Login";
datagridcol.DataField = de.Properties["sAMAccountName"].Value.ToString());
DataGrid1.Columns.Add(datagridcol);
datagridcol = new BoundCoulmn();
datagridcol.HeaderText = "Email Address";
datagridcol.DataField = de.Properties["Mail"].Value.ToString());
DataGrid1.Columns.Add(datagridcol);
datagridcol = new BoundCoulmn();
datagridcol.HeaderText = "First Name";
datagridcol.DataField = de.Properties["Mail"].Value.ToString());
DataGrid1.Columns.Add(datagridcol);
datagridcol = new BoundCoulmn();
datagridcol.HeaderText = "First Name";
datagridcol.DataField = de.Properties["GivenName"].Value.ToString());
DataGrid1.Columns.Add(datagridcol);
datagridcol = new BoundCoulmn();
datagridcol.HeaderText = "Department";
datagridcol.DataField = de.Properties["department"].Value.ToString());
DataGrid1.Columns.Add(datagridcol);
}
catch(Exception e)
{
lblMessage.text = e.Message;
}
}
}
I have successfully connected to Active directory using asp.net c#
But problem is I want to display all the users and there attribute in my datagrid i.e user login name,emai, department,title etc . Please correct me where I am doing mistake. Thanks in advance....
string dom = "MyDomain";
DirectoryEntry entry = new DirectoryEntry("LDAP://" + dom);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = ("(objectClass=user)");
foreach(SearchResult resEnt in mySearcher.FindAll())
{
try
{
DirectoryEntry de=resEnt.GetDirectoryEntry();
'adding bound columns to the datagrid
BoundCoulmn dataGridCol = new BoundCoulmn();
datagridcol.HeaderText = "User Login";
datagridcol.DataField = de.Properties["sAMAccountName"].Value.ToString());
DataGrid1.Columns.Add(datagridcol);
datagridcol = new BoundCoulmn();
datagridcol.HeaderText = "Email Address";
datagridcol.DataField = de.Properties["Mail"].Value.ToString());
DataGrid1.Columns.Add(datagridcol);
datagridcol = new BoundCoulmn();
datagridcol.HeaderText = "First Name";
datagridcol.DataField = de.Properties["Mail"].Value.ToString());
DataGrid1.Columns.Add(datagridcol);
datagridcol = new BoundCoulmn();
datagridcol.HeaderText = "First Name";
datagridcol.DataField = de.Properties["GivenName"].Value.ToString());
DataGrid1.Columns.Add(datagridcol);
datagridcol = new BoundCoulmn();
datagridcol.HeaderText = "Department";
datagridcol.DataField = de.Properties["department"].Value.ToString());
DataGrid1.Columns.Add(datagridcol);
}
catch(Exception e)
{
lblMessage.text = e.Message;
}
}
}