[/code]"> [/code]"> [/code]">
It`s a good day to die....

I`m trying to make & modify windows application about AD group and users.

This application works like this.

Users choose property and mapping it from source data(DB or Excel files...)

And press sync start button, that properties put into the AD User.

But When I set AD user`s properties, it throws exception like this in DirectoryEntry.CommitChanges(); block.

The directory
service cannot perform the requested operation on the RDN attribute of an object.

Sadly I`m a newbie of Active Directory, I don`t know how to solve it... Please help me.

Code is below. [code]void CreateADUser(string ppk,string pk,DataRow row) { string pass = GetPass(pk,row,LogSections.AD); DirectoryEntry addept = adm.FindOU(ppk); string sOU = adm.GetPrincipalPath(addept); var aduser = adm.CreateNewUser(sOU, pk, pass, pk, null, null, adm.sDomain); SetAdUserProperties(pk, pass, row); MoveUser(ppk,pk); } void SetAdUserProperties(string pk,string pass,DataRow row) { if (row == null) return; List<ADMapping> MappingPatterns = GetAdMappings(Words.User,false); var colnames = Tool.GetColNames(row); var aduser = adm.GetUser(pk); var de=aduser.GetUnderlyingObject() as DirectoryEntry; foreach (var ADMap in MappingPatterns) { string val = ADMap.Mapping; val=Util.ReplaceColPattern(val, row); SetProperty(de, ADMap.CN, val); } if (!string.IsNullOrWhiteSpace(pass)) { var UserPkColumn = AppConfigHelper.GetAppString(Words.SourceUserPKColumn); UserPkColumn = Util.GetActualColName(UserPkColumn); aduser.SetPassword(pass); QueryHelper.Update(QueryHelper.ConnectionString, Words.ShadowUserTable ,new SqlParameter[] { new SqlParameter("@passwd", pass) } , new SqlParameter("@"+UserPkColumn,pk)); } aduser.Save(); } public void SetProperty(DirectoryEntry oDE, string sPropertyName, object sPropertyValue) { if (sPropertyValue != null && !string.IsNullOrWhiteSpace(sPropertyValue.ToString())) { if (oDE.Properties.Contains(sPropertyName)) { oDE.Properties[sPropertyName].Value = sPropertyValue; } else { oDE.Properties[sPropertyName].Add(sPropertyValue); } try { oDE.CommitChanges(); //exception here. oDE.Close(); } catch (Exception) { } } }[/code]


JLCPCB – Prototype 10 PCBs for $2 (For Any Color)

China’s Largest PCB Prototype Enterprise, 600,000+ Customers & 10,000+ Online Orders Daily
How to Get PCB Cash Coupon from JLCPCB: https://bit.ly/2GMCH9w

Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir