karephre
asked on
ASP.Net C# and Active Directory error "c# index was out of range. Must be nonnegative and less than the size of the collection"
hello Experts,
I have a bit of code that binds to on Active Directory user, disable it, and move it to a cleanup OU. I tried to add a line of code that will write to the description attriubute on the object, but I keep getting the error "c# index was out of range. Must be nonnegative and less than the size of the collection", once the code reaches userMove.Properties["descr iption"][0 ] .
Below is a snipped of the code"
I have a bit of code that binds to on Active Directory user, disable it, and move it to a cleanup OU. I tried to add a line of code that will write to the description attriubute on the object, but I keep getting the error "c# index was out of range. Must be nonnegative and less than the size of the collection", once the code reaches userMove.Properties["descr
Below is a snipped of the code"
try
{
AccDisable ad = new AccDisable();
ad.Disable(userDN);
// Bind to the object to be moved.
DirectoryEntry userMove = new DirectoryEntry("LDAP://" + userDN, systemUser, systemPw);
// Update the Description attribute on the user
userMove.Properties["description"][0] = "no NASW Authentication has taken place in the past" + dayCreatRound;
// Use the MoveTo property to define the new container you want to move the object to.
// userMove.MoveTo(new DirectoryEntry("LDAP://OU=OVER_45_DAYS_USER,OU=CLEANUP,OU=domain.com", systemUser, systemPw));
}
catch (InvalidOperationException InvOpEx)
{
// Handle InvalidOperationException.
string messageEx = "Could not move "+InvOpEx.Message;
lm.WriteLogNoDS(messageEx,logLocation);
}
catch ( Exception Ex)
{
// Handle all other errors
string messageEx = "Could not move " + Ex.Message;
lm.WriteLogNoDS(messageEx, logLocation);
}
#endregion
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER