C# Get AD users info by bulk employee ID

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Dear Exprt,
One more time i am initialting this topic for your usual support please assist...
public DataTable ADEmpid(string Num)
{
try
{
DirectoryEntry entry = new DirectoryEntry("LDAP://" + GetSystemDomain());
DirectorySearcher Dsearch = new DirectorySearcher(entry);

Dsearch.Filter = "(&((&(objectCategory=Person)(objectClass=User)))(extensionAttribute2=" + Num + "))";
DataTable dt = new DataTable();
dt.Columns.Add("LogonName");
dt.Columns.Add("Name");
dt.Columns.Add("Employee ID");
dt.Columns.Add("Company");
SearchResult sResultSet = Dsearch.FindOne();
{
DataRow dr = dt.NewRow();
dr[0] = (GetProperty(sResultSet, "samaccountname"));
dr[1] = (GetProperty(sResultSet, "name"));
dr[2] = (GetProperty(sResultSet, "ExtensionAttribute2"));
dr[3] = (GetProperty(sResultSet, "Company"));

dt.Rows.Add(dr);
}
return dt;

}
catch (Exception ex)
{
return null;
}
}
//==========================
// On Button
//==========================
private void button2_Click(object sender, EventArgs e)
{
StreamReader myReader = new StreamReader("EmpIDs.txt");
string line = "";
while (line != null)
{
line = myReader.ReadLine();
if (line != null)
{
dataGridView1.DataSource = ADEmpid("line");
}
}
myReader.Close();

}
receive error : - {"Object reference not set to an instance of an object."} System.Exception {System.NullReferenceException}
Support@Mytechnet.me

View the full article
 
Back
Top