|
-
November 17th, 2008, 03:01 PM
#1
Constraint Violation Problem
How can I check the manager property using the distinguishedName for updating?
I am trying to update the manager property in Active Directory using data from a database. I need to check if the manager name from the db is the same as in Active Directory, if the name is not the same don't do nothing. If the name is the same update the name for the manager.
I found this code over the Internet but I don't understand it. I what the guy refers to with dc1.ad.... + dnOfManager. I know what the domain is but not the rest. Any help will be very appreciated.
Code:
if(DirectoryEntry.Exists("LDAP://dc1.ad.domain.com/" + dnOfManager))
{
// update user object with dnOfManager
}
else
{
// manager object does not exist
}
This is what I am trying:
try {
string supervisor = "";
string lastName = "";
string firstName = "";
string mngr = "";
supervisor = oEmployee.Manager;
if (supervisor.Contains(",")) {
string[] split = supervisor.Split(new Char[] { ',' });
lastName = split[0];
firstName = split[1];
mngr = "CN=" + lastName + @"\," + firstName + ",CN=Users,DC=domain,DC=net";
}
if (DirectoryEntry.Exists("LDAP://" + "CN=" + lastName + @"\, " +
firstName + "," + "CN=users,DC=domain,DC=net")) {
if (supervisor != String.Empty) {
dentry.Properties["manager"].Value = mngr;
}
}
else {
Console.WriteLine("Could not update Manager Property in Active Directory.");
if (flE.Exists) {
using (sw = flE.AppendText()) {
sw.WriteLine("===========================");
sw.WriteLine(DateTime.Now.ToShortDateString() +
" " + DateTime.Now.ToShortTimeString());
sw.WriteLine("Could not update Manager for: " + oEmployee.EmpFullName + " : " + oEmployee.empId);
sw.WriteLine(" ");
sw.WriteLine("===========================");
}
}
}
}
catch (Exception e) {
if (flE.Exists) {
using (sw = flE.AppendText()) {
sw.WriteLine("===========================");
sw.WriteLine(DateTime.Now.ToShortDateString() +
" " + DateTime.Now.ToShortTimeString());
sw.WriteLine("Error: " + e.Message);
sw.WriteLine("Trying to update the Manager Property in Active Directory.");
sw.WriteLine("EmployeeID: " + oEmployee.empId);
sw.WriteLine(" ");
sw.WriteLine("===========================");
}
}
}
Last edited by member_1222; November 18th, 2008 at 07:24 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|