473,386 Members | 2,078 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.

DirectoryEntry.Rename method

12
Writing a .Net 4 C# console application to add/update Active Directory user objects.

I am using the DirectoryEntry.Rename method to rename the cn property of user objects.

If I understand the MS documentation for the Rename method - - If UsePropertyCache is true (which is the default) then I need to call CommitChanges on the object to make the rename action permanent.

However, When I execute the following code - the Rename action becomes permanent without a CommitChanges.

Expand|Select|Wrap|Line Numbers
  1. DirectoryEntry Uentry = result.GetDirectoryEntry();
  2. Uentry.Rename("cn=" + newValue);      
  3.  
Any advice on this would be appreciated?
Jan 21 '14 #1
5 6872
Luk3r
300 256MB
Do you have code that is specifying what a "result" is? What I mean by that is, your DirectoryServices.SearchResult must return a result before it can actually change anything.

I'm not sure how similar C# and VB are, but here's a small example in VB to give you something to go by. I tested this and it worked fine:
Expand|Select|Wrap|Line Numbers
  1. Dim ADServer As String = "LDAP://DC1"
  2.         Dim dEntry As New DirectoryServices.DirectoryEntry(ADServer)
  3.         Dim Searcher As New DirectoryServices.DirectorySearcher(dEntry)
  4.         Searcher.Filter = ("(cn=Test User)")
  5.         Dim entryResult As DirectoryServices.SearchResult
  6.  
  7.         Try
  8.             For Each entryResult In Searcher.FindAll()
  9.                 entryResult.GetDirectoryEntry.Rename("cn=Test Test")
  10.             Next
  11.         Catch ex As Exception
  12.             MsgBox(ex.ToString)
  13.         End Try
Jan 21 '14 #2
dev99
12
Thanks for the reply. Yes my C# code is similar. In your code above - you do not specify CommitChanges() after the Rename. Don't you need this to make the Rename move from an update to your property cache to be a permanent change in the Directory?
Jan 21 '14 #3
Luk3r
300 256MB
If you have access to create a user in Active Directory, I suggest you do so. I didn't use CommitChanges() and my Test User account got switched to "Test Test" perfectly. So, if you can, create a test account, try your code without Commit and/or with Commit. If using CommitChanges() makes a difference, then keep it. Otherwise, omit it :)
Jan 21 '14 #4
dev99
12
Thanks. I did discover that the Rename is permanent without requiring a CommitChanges. But that is contrary to MicroSoft docs.

The docs state that I must specifically set UsePropertyCache="false" (default is "true") in order for the Rename to be permanent by itself without the CommitChanges.

So I'm just trying to verify if I understand the docs correctly. I'm also wondering if a CommitChanges happens when the C# script ends. Maybe that is where the update happens...?
Jan 21 '14 #5
Luk3r
300 256MB
According to Microsoft Documentation, you are correct. So I retract my other statement and suggest that you CommitChanges after making a change. I thought it was only used when Adding or Removing, not updating. My apologies, and cheers!
Jan 21 '14 #6

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

Similar topics

1
by: Walter Zydhek | last post by:
Can anyone help with the use of the Invoke method of a Directory Entry object? I am using vb.net. I am trying to invoke the get_Filter method of the IIS://LocalHost directory entry, and get the...
1
by: Jason Heyes | last post by:
Is there a function in the standard C++ library that serves the purpose of renaming a file? If not, do I have to use boost or operating system specific code? Thanks.
1
by: Gudni G. Sigurdsson | last post by:
Hi. I want to walk a certain directory and rename all it´s subdirectories. The Directory class has a method Move but no Rename method. Should I then use Move instead? Gudni
0
by: Querton Pierre-Benoit | last post by:
Hello, I develop a class to control IIS throw ADSI. But is seems that some method doesn't work with IIS. To be more clear ;) When I do the following code : DirectoryEntry w3svc = new...
3
by: Saradhi | last post by:
Hi All, Here I am facing a performance problem with the TreeView Node renaming. I am displaying a hierarchy Data in a treeview in my Windows C# Application. My tree view represents an...
4
by: Randy | last post by:
Ok, something simple like this shouldn't be so hard to find. I'm confounded as to why the File class doesn't have a Rename method. Can someone please tell me how to rename a file in C#? Thanks
1
by: William H. Burling | last post by:
i have a nest of vb.vanilla collections. CollectionofHotelData.item("great Pequot").item("2000").item(22) The above works. I wrote the code that constructs the nested collections and i can...
2
by: rakesh_nits | last post by:
Hi All, I have a very simple problem .I want to rename a directory using C#.But I am not changing the location of directory neither its name(letters) just the case(from upper to lower or vice a...
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...
10
by: arpesystem | last post by:
Hi all, Fist of all, sorry for my bad English. I have a database with a lot of articles. Each article has an image, but this image is stored in a folder called c:\Images. Now I need to rename all...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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...

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.