I have the folowwing code that works awesome. But I need to be able to
filter out the accounts that are disabled. Any ideas on how I might do
this?
public DataSet FindUsers(string sFilter, string[] columns, string path,
bool useCached)
{
// try to retrieve from cache first
HttpContext context = HttpContext.Current;
DataSet userDS = (DataSet)context.Cache[sFilter];
if((userDS == null) || (!useCached))
{
// setup the searching entries
DirectoryEntry deParent = new DirectoryEntry(path);
deParent.Username = ConfigurationSettings.AppSettings
["adEDir.Username"];
deParent.Password = ConfigurationSettings.AppSettings
["adEDir.Password"];
deParent.AuthenticationType =
AuthenticationTypes.Secure;
DirectorySearcher ds = new
DirectorySearcher(deParent, sFilter, columns);
ds.PageSize = 1000;
ds.Sort = new SortOption("displayName",
SortDirection.Ascending);
using(deParent)
{
// setup the dataset that store
the results
userDS = new DataSet("userDS");
DataTable dt = userDS.Tables.Add
("users");
DataRow dr;
// add each paramater as columns
foreach (string prop in columns)
{
dt.Columns.Add(prop,
typeof(string));
}
foreach (SearchResult sr in
ds.FindAll())
{
dr = dt.NewRow();
foreach (string prop in
columns)
{
if
(sr.Properties.Contains(prop))
{
dr[prop]
= sr.Properties[prop][0];
}
}
dt.Rows.Add(dr);
}
}
// Cache it for later, with 3 minute
sliding window
context.Cache.Insert(sFilter, userDS,
null, DateTime.MaxValue, TimeSpan.FromSeconds(180));
}
return userDS;
}