473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Udating Active Directory user Information

Hi,

I got a console application that updates active directory users, the information to be updated in active directory comes from a database table. This is my problem:
right now the application works if none of the objects like (telephoneNumber, department, etc..) to be updated into active directory are not null. If an object is null I get an error. I try with an if condition, it does not give any error but does not updates the object property. My brain is very fried with this I can't think of anything else to make it work. I include part of my class that search for an user and updates ad with his information from the database.

This is what I try so far:

if (dentry.Properties["homePhone"].Value != null) {
dentry.Properties["homePhone"].Value = oEmployee.HomePhone; }

if (dentry.Properties.Contains("homePhone")) {
dentry.Properties["homePhone"].Value = oEmployee.HomePhone; }

if (restEnt.Properties.Contains("homePhone")) {
dentry.Properties["homePhone"].Value = oEmployee.HomePhone; }

if (dentry.Properties.Contains(oEmployee.HomePhone)) {
dentry.Properties["homePhone"].Value = oEmployee.HomePhone; }

if (restEnt.Properties.Contains(oEmployee.HomePhone)) {
dentry.Properties["homePhone"].Value = oEmployee.HomePhone; }


CODE:

public SortedList<string, clsEmployee> GetEmpSqlAll() {
// Collection of employee records
SortedList<string, clsEmployee> colEmployee = new SortedList<string, clsEmployee>();
SqlConnection sqlConn = new SqlConnection(connString);
sqlConn.Open();

string cmdString = "SELECT * FROM view_database_data_to_be_inserted_in_AD";
SqlCommand myCmd = new SqlCommand(cmdString, sqlConn);
try {
SqlDataReader dataReader = myCmd.ExecuteReader();
if (dataReader != null) {
while (dataReader.Read()) {
oEmployee = new clsEmployee();
oEmployee.empId = dataReader["employeeId"].ToString();
oEmployee.Department = dataReader["Department"].ToString();
oEmployee.Manager = dataReader["Supervisor"].ToString();
oEmployee.TelephoneNumber = dataReader["WorkPhone"].ToString();
oEmployee.Nextel = dataReader["NextelDC"].ToString();
oEmployee.Mobile = dataReader["Cell"].ToString();
oEmployee.Pager = dataReader["Pager"].ToString();
oEmployee.HomePhone = dataReader["Phone"].ToString();
colEmployee.Add(oEmployee.empId, oEmployee);
}
}
else {
Console.WriteLine("Employees not found.");
}
}
catch (Exception e) {
Console.WriteLine("Error: " + e.Message);
return colEmployee;
}
sqlConn.Close();
sqlConn.Dispose();
return colEmployee;
}

public void ModifyUsers(SortedList<string, clsEmployee> colEmployee) {
DirectoryEntry de = GetDirectoryEntry();
DirectorySearcher dirsearcher = new DirectorySearcher(de);
dirsearcher.Filter = "(&(objectCategory=person)(objectClass=user))" ;

foreach (SearchResult restEnt in dirsearcher.FindAll()) {
DirectoryEntry dentry = restEnt.GetDirectoryEntry();
object prop = dentry.Properties["employeeId"];
if (prop != null) {
object empId = dentry.Properties["employeeId"].Value;
if (empId != null) {
clsEmployee emp = null;
try {
emp = colEmployee[empId.ToString()];
}
catch {
// do nothing
}
if (emp != null) {
// Update the information
Console.WriteLine(emp.empId);

if (dentry.Properties.Contains("telephoneNumber"))
{
dentry.Properties["telephoneNumber"].Value = oEmployee.TelephoneNumber;
}

if (dentry.Properties.Contains("ipPhone"))
{
dentry.Properties["ipPhone"].Value = oEmployee.Nextel;
}

if (dentry.Properties["mobile"].Value != null)
{
dentry.Properties["mobile"].Value = oEmployee.Mobile;
}

if (dentry.Properties["pager"].Value != null)
{
dentry.Properties["pager"].Value = oEmployee.Pager;
}

if (dentry.Properties.Contains("homePhone"))
{
dentry.Properties["homePhone"].Value = oEmployee.HomePhone;
}

//If anyone knows how to insert a name with last name into the manager property, please reply with example

//dentry.Properties["manager"].Value = oEmployee.Manager;

if (dentry.Properties.Contains("department"))
{
dentry.Properties["department"].Value = oEmployee.Department;
}

dentry.CommitChanges();
dentry.Close();
}

Any help or code examples will be very appreciated.

Thanks
Aug 26 '08 #1
0 1432

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Toufani | last post by:
Hi everybody, I want to retrieve information about objects in active directory windows 2000 and their properties. I got some codes that don't work absolutely. for example I can't retrieve users...
12
by: JIM.H. | last post by:
Hello, Here is my code that I got from internet and I am assuming this give me e-mail address of the people in the active directory. Private Sub Page_Load(ByVal sender As System.Object, ByVal e...
6
by: Leo_Surf | last post by:
Hello, I need your help adding user in Active Directory from ASP.net website. Could any one provide me the complete code for the html page. As this is my curriculam project and I dont have any...
3
by: Luis Esteban Valencia | last post by:
Hello gusys, Is it possible to make my asp.net application add users to the AD , I also want to be able to delete users, modify their information, everything through a website. Thanks for the...
3
by: Adrian Parker | last post by:
At the moment, we have a simple user id / password entry screen to login to our website, the data credentials are held in our database. We've now been asked to integrate with active directory so...
10
by: Hriday | last post by:
Hi there, Please help me..It is urgent This is Hriday, working on windows authentication with Active Directory... My requirment is when a user sends a request to my web Applicatoin I want to...
2
by: Alpha | last post by:
I need to retrieve and set information in Active Directory in a new project that I'll be working on. I went to Amazon.com to look for a good book on this subject but found books on this subject...
0
by: Chung Leong | last post by:
In this brief tutorial I'll describe how you retrieve information from an Active Directory through the OLE-DB extension. While it is possible to use the LDAP extension to achieve the same goal, as...
7
by: Vio | last post by:
Hello everyone, i currently a beginner in php. I want to ask about Win2003 Active Directory users. Is it possible to retrieve Win2003 AD (just username & password) with php. I'm currenty...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.