Hello Guru's
Thanks so much for earlier help to achieve AD .
At present am having trouble to include AD function in my code.
Hope some will guide me in the right direction
what am trying to do is get the value from webservice and check with AD and retrieve the name and update the database.
Here is my code
public ArrayList GetEmployeesFromService()
{
DirectoryEntry entry = new DirectoryEntry("GC://Test", "Test\\Test", "Ld@Test", AuthenticationTypes.Secure);
System.DirectoryServices.DirectorySearcher search = new System.DirectoryServices.DirectorySearcher(entry);
ArrayList resultList = new ArrayList();
foreach (EmployeeExport item in svcWrapper.GetEmployees)
{
resultList.Add(item.Department);
System.Data.SqlClient.SqlConnection sqlConnection1 = new System.Data.SqlClient.SqlConnection(@"Data Source=SYDTESTSVR05;Initial Catalog=DLAPGateway_DEV;Integrated Security=SSPI");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
search.Filter = "(otherpager=" + item.EmployeeNumber + ")";
SearchResult result = search.FindOne();
ResultPropertyCollection fields = result.Properties;
foreach (String ldapField in fields.PropertyNames)
{
if (ldapField == "name")
string name;
name =ldapField.ToString().Trim();
}
cmd.CommandText = "INSERT Person (EmployeeNo,NamePrefix,FirstName, MiddleName, LastName, NameSuffix,Contractor,HighestEducationalLevel, BirthDate, Gender ) VALUES("
+ item.EmployeeNumber + ","
+ "'" + item.Title + "'" + ","
+ "'" + item.PreferredName + "'" + ","
+ "'" + item.MiddleName.Replace("'", "''") + "'" + ","
+ "'" + item.Surname.Replace("'", "''") + "'" + ","
+ "'" + item.Suffix + "'" + ","
+ "'" + item.PayPoint + "'" + ","
+ "'" + item.HighestEducationLevel + "'" + ","
+ "'" + item.BirthDate + "'" + ","
+ "'" + item.Sex + "'" + ")";
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
cmd.ExecuteNonQuery();
sqlConnection1.Close();
}
return resultList;
}