473,419 Members | 1,565 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,419 software developers and data experts.

DirectoryServices Add/Remove Manager to Direct Report

Greetings,

I am building a ASPX UI that will allow a HR representative manage the AD
Organization. I have a class that wraps a lot of AD work and I do things
like change password and update the GAL with Business information. I have
been able to write the code to get list of Direct Reports for a given user,
no problem. However, I am having trouble with how to set the 'manager' of a
AD user. Is it a property or a invoke function?

My code is simple like this...

public void AddDirectReport( string ManagerAlias, string UserAlias )

{

DirectoryEntry deManager = GetUser(ManagerAlias);

DirectoryEntry deDirectReport = GetUser(UserAlias);

this.SetProperty( deDirectReport, "manager", this.GetProperty( deManager,
"dn" ) );

deManager.Close();

deDirectReport.Close();

}

public void SetProperty(DirectoryEntry oDE, string PropertyName, string
PropertyValue)

{

//check if the value is valid, otherwise dont update

if(PropertyValue !=string.Empty)

{

//check if the property exists before adding it to the list

if(oDE.Properties.Contains(PropertyName))

{

oDE.Properties[PropertyName][0]=PropertyValue;

oDE.CommitChanges();

}

else

{

oDE.Properties[PropertyName].Add(PropertyValue);

oDE.CommitChanges();

}

}

}

I have tried passing just the user alias instead of the Dn, and I get a
'Constrain violation error'. The code above, actually does not throw an
error, but it does not add the Manager either. Of course, GetUser() and
SetProperty() and GetProperty() are other members of the class to get the
Directory Entry of a user.

I have tried passing an empty string as the property value to try to remove
an already established Manager, but does not seem to work. The account that
makes the AD connection is a domain admin so it has rights..plus my other AD
code is running fine with this account on my staging environment. I have
waited 15 min to see if DC has been replicated, but no change to the AD
users I am testing with.

I have found example code using VB and ADSI calls, but C# and
DirectoryService namespace is scarce. The VB stuff looks like I am doing
the correct calls, but maybe I am missing something.

Anyone have experience in doing this with C# will help me greatly.

Thanx

Micah


Nov 17 '05 #1
0 2912

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: kovac | last post by:
The System.directoryservices.dll has an error, and this error was described in http://support.microsoft.com/default.aspx?scid=kb;en-us;839424 At the moment we have Framework version v1.0.3705 and...
3
by: Sean | last post by:
I figured I'd start this post on the .NET general forum instead of the ADSI forum but feel free to nudge me along if I am looking in the wrong place. I am working with System.DirectoryServices...
1
by: Gaab | last post by:
Hi Folks, After the weekend I wanted to start working on my c#/asp.net project, but when I tried to open it on my machine i got the following error: Compilation Error Description: An error...
1
by: Stephanie Stowe | last post by:
Hi. I am trying to read information out of the IIS metabase (v5.1). Observe the following code: using System; using System.DirectoryServices; using System.Reflection; namespace ADSI1 {...
6
by: Rich Crusco via DotNetMonster.com | last post by:
I am looking for a way to convert the following vbs script to c# Const ADS_SECURE_AUTHENTICATION = 1 strADMIN = "adminaccount" strPASSWORD = "password" strUSER = "useraccount" Set dso =...
5
by: Keith Jakobs, MCP | last post by:
Hi All.... I'm having a HECK of a time connecting to Active Directory using VB in Visual Studio.NET 2003. Can anyone PLEASE help me? All I am trying to do is list the current members of our...
1
by: killbill | last post by:
Hi All, I cannot figure out how i can delete user in AD with DirectoryServices using ldap query? Thanks
7
by: aamirghanchi | last post by:
Hi, I had .Net 1.1 app that worked fine. I recently migrated it to 2.0 but am getting compilation errors, among which DirectoryServices classes are not being recognized by the VS 2005 at build...
7
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I am using this code to get groups for a user and getting a error (5) on the GetAuthorizationGroups() function . There are two domains. This function works on the local domain but does not work...
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.