473,830 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DirectoryServic es 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(Manager Alias);

DirectoryEntry deDirectReport = GetUser(UserAli as);

this.SetPropert y( deDirectReport, "manager", this.GetPropert y( deManager,
"dn" ) );

deManager.Close ();

deDirectReport. Close();

}

public void SetProperty(Dir ectoryEntry oDE, string PropertyName, string
PropertyValue)

{

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

if(PropertyValu e !=string.Empty)

{

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

if(oDE.Properti es.Contains(Pro pertyName))

{

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

oDE.CommitChang es();

}

else

{

oDE.Properties[PropertyName].Add(PropertyVa lue);

oDE.CommitChang es();

}

}

}

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
DirectoryServic e 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 2939

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

Similar topics

0
2183
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 I have remove System.directoryservices.dll from current Framework version v1.0.3705. In state of old version I load die new System.directoryservices.dll from the Framework version v1.1.4322. I work with the following function of Joe Kaplan...
3
2927
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 to connect up to Active Directory and make a couple of queries. The trouble starts as soon as I attempt to compile this thing. I receive "Type 'System.DirectoryServices.SearchResultCollection' has no constructors." from the following code. ...
1
16251
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 occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
1
4862
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 { class ConfigIIS
6
13328
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 = GetObject("WinNT:") Set srv = DSO.OpenDSObject("WinNT://servername/LanmanServer", strADMIN, strPASSWORD, ADS_SECURE_AUTHENTICATION) Set colResources = srv.Resources
5
2072
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 Active Directory on a web page. If I can connect to the AD interfaces, then I think I can handle it from there. I do have a VS.NET C# project successfully working and enumerating names,
1
4030
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
2821
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 time. I can clearly see the reference to System.DirectoryServices 2.0.0 GAC in the reference list and there is no error where the Imports System.DirectoryServices statement is. Its listing errors all over for the classes under its namespace:
7
16348
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 on the other domain. Other functions work on the other domain like get all the users and get all the groups and I can validate users on the other domain so I think I am communciating with the other domain OK just not with the...
0
10774
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10489
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10525
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9314
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7746
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5617
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.