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

Problems with DirectoryEntry

I am working with Active Directory in C# and trying to read and set certain
attributes. To set an attribute, I have the following code:

DirectoryEntry de = new DirectoryEntry(); //This is assigned to a
DirectoryEntry from a search result.

de.Properties["telephoneNumber"].Value = telephoneNumber;
de.CommitChanges();

The code above works perfectly unless telephoneNumber is an empty string.
How can I either assign an empty string to the value, or remove any value
that is there?
Nov 15 '07 #1
5 6681
How about de.Properties["telephoneNumber"].Clear?

Colby
Nov 15 '07 #2
Thank you, but that didn't seem to work either.

"Colby Africa" <co**********@gmail.comwrote in message
news:29**********************************@y5g2000h sf.googlegroups.com...
How about de.Properties["telephoneNumber"].Clear?

Colby

Nov 16 '07 #3
"Drew Burchett" <dr***@brtc.netwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
Thank you, but that didn't seem to work either.

"Colby Africa" <co**********@gmail.comwrote in message
news:29**********************************@y5g2000h sf.googlegroups.com...
>How about de.Properties["telephoneNumber"].Clear?

Colby

Are you sure that this (optional) property exists, you cant change the
value of a non-existing property, you have to add it first like this:

de.Properties["telephoneNumber"].Add(""); // add property and set it's
value to an empty string.

Willy.
Nov 16 '07 #4
Yes. I've used ADSI edit to go into the Active Directory and see for
certain that the property exists.

Also, in stepping through the code, I found that setting the property to
empty or calling Clear either one will remove the property, but it appears
that it never gets saved when I call CommitChanges. Not sure what would be
causing that since CommitChanges never throws an exception and won't return
any error codes.

"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:eJ*************@TK2MSFTNGP03.phx.gbl...
"Drew Burchett" <dr***@brtc.netwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
>Thank you, but that didn't seem to work either.

"Colby Africa" <co**********@gmail.comwrote in message
news:29**********************************@y5g2000 hsf.googlegroups.com...
>>How about de.Properties["telephoneNumber"].Clear?

Colby


Are you sure that this (optional) property exists, you cant change the
value of a non-existing property, you have to add it first like this:

de.Properties["telephoneNumber"].Add(""); // add property and set it's
value to an empty string.

Willy.


Nov 16 '07 #5
"Drew Burchett" <dr***@brtc.netwrote in message
news:uJ**************@TK2MSFTNGP04.phx.gbl...
Yes. I've used ADSI edit to go into the Active Directory and see for
certain that the property exists.

Also, in stepping through the code, I found that setting the property to
empty or calling Clear either one will remove the property, but it appears
that it never gets saved when I call CommitChanges. Not sure what would
be causing that since CommitChanges never throws an exception and won't
return any error codes.

"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:eJ*************@TK2MSFTNGP03.phx.gbl...
>"Drew Burchett" <dr***@brtc.netwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
>>Thank you, but that didn't seem to work either.

"Colby Africa" <co**********@gmail.comwrote in message
news:29**********************************@y5g200 0hsf.googlegroups.com...
How about de.Properties["telephoneNumber"].Clear?

Colby


Are you sure that this (optional) property exists, you cant change the
value of a non-existing property, you have to add it first like this:

de.Properties["telephoneNumber"].Add(""); // add property and set it's
value to an empty string.

Willy.


Ok I see, the thelephoneNumber cannot be an empty string, *empty* strings
(strings with 0 length) are not valid attribute in AD, that means that when
you set a value to "" , that the property gets deleted.
So, you need to set the value to a valid number or set it to a single space
" " or whatever value that is indicative for a non valid number. Much better
IMO is to delete the property if no value exists for the property.

Willy.
,


Nov 16 '07 #6

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

Similar topics

2
by: Jessica | last post by:
When I create a single LDAP ActiveDirectory user and use DirectoryEntry.Invoke("SetPassword"...), the user is created and the password is set with no problems. However, when I try to add more...
0
by: Sergej Pioch | last post by:
Hello everybody, im trying hard to automate some tasks in a huge windows environment. This lend me to bigger problems while trying to create new global security groups within active directory....
2
by: Jay | last post by:
Please excuse the double post if your reader shows this as a new and as a reply. I can only use the web interface and it puts my reply 34 pages in. I am getting an error while trying to do a...
2
by: AbdSol | last post by:
I wanted to know why the output is different & also like to know if C# i can get the user name using DirectoryEntry > find. C# String myADSPath = ("WinNT://"+...
0
by: Ken Yee | last post by:
Anyone know how to do this in C#? It's pretty trivial in VB, but is being a PITA in C#. I can call the Start/Stop methods w/o any problems, but I can't figure out how to read the current status...
0
by: Tim::.. | last post by:
Hi can someone please tell me why I can't put the following LDAP string into my web.config fill as an <appSetting> <appSettings> <add key="strLDAP" value="'LDAP://doamin.domain.com',...
1
by: Marek Kopanski | last post by:
Hallo, I have to change a user password in my ASP.NET project. In the first step I was trying to change my own passwort (as example) in Active Directory on my Server, but already at this point I...
1
by: Joanne | last post by:
I'm wondering if anyone has come across this problem before - it's got me stumped (but then again, I don't know a great deal about AD!!) In a specific set of circumstances, we get a really useful...
2
by: DavidADEW | last post by:
need a ASP.NET C# web page that lets a user enter their NT user name and password and passes to NT to see if they are a valid NT login. I am aware of the System.DirectoryServices.DirectoryEntry...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.