Wednesday, 25 June 2014

SearchResultCollection to DataTable

SearchResultCollection mySearchResultColl = results;
DataTable result = new DataTable();
result.Columns.Add(“name”);
result.Columns.Add(“mail”);
foreach (SearchResult sr in mySearchResultColl)
{
DataRow dr = result.NewRow();
DirectoryEntry de = sr.GetDirectoryEntry();
dr["name"] = de.Properties["Name"].Value;
dr["mail"] = de.Properties["mail"].Value;
result.Rows.Add(dr);
de.Close();
}
GridView1.DataSource = result;
GridView1.DataBind();