pusalaanita
IS-IT--Management
Hello,
I am tyring to retrieve data from Active Directory and dipalying in a datatable and adding it to the GridView.
The Datatable is added to the gridview but the values r not dipalyed.
Below is the code could anyone trace out the problem and solve the problem.
public DataTable GetUsers()
{
DataTable dt = new DataTable();
dt.Columns.Add("Navn");
dt.Columns.Add("Direktenr");
dt.Columns.Add("Telefon");
dt.Columns.Add("Faks");
dt.Columns.Add("Mobil");
dt.Columns.Add("StreetAddress");
dt.Columns.Add("PostalAddress");
dt.Columns.Add("EPost");
DirectoryEntry de = GetDirectoryEntry();
DirectorySearcher ds = new DirectorySearcher(de);
ds.Filter="(objectClass=user)";
ds.SearchScope = SearchScope.Subtree;
SearchResultCollection results= ds.FindAll();
foreach (SearchResult result in results)
{
DataRow dr = dt.NewRow();
DirectoryEntry dey = GetDirectoryEntry();
dr["Navn"] = dey.Properties["cn"].Value;
dr["Direktenr"] = dey.Properties["telephonenumber"].Value;
dr["Telefon"] = dey.Properties["homephone"].Value;
dr["Faks"] = dey.Properties["facsimailtelephone"].Value;
dr["Mobil"] = dey.Properties["mobile"].Value;
dr["StreetAddress"] = dey.Properties["streetAddress"].Value;
dr["PostalAddress"] = dey.Properties["postalcode"].Value;
dr["EPost"] = dey.Properties["mail"].Value;
dt.Rows.Add(dr);
dey.Close();
}
de.Close();
return dt;
}