locked
Updating an existing EmployeeID RRS feed

  • Question

  • User-246688969 posted

    We're updating our AD with Employee IDs for the first time.  We have a simple function which provides the ability to add the employeeID attribute if it does not exist or update it if it does (well, that's the plan anyway). 

    private void SetProperty(DirectoryEntry de, string propertyName, string propertyValue)
    {
         if (de.Properties.Contains(propertyName))
              de.Properties[propertyName][0] = propertyValue;
         else
              de.Properties[propertyName].Add(propertyValue);
    }

    Updating an employee with an existing employeeID generates the exception below:

    System.NotSupportedException: Specified method is not supported. at System.DirectoryServices.PropertyValueCollection.set_Item(Int32 index, Object value) at ADSITest.Codebehind.Main.SetProperty(DirectoryEntry de, String propertyName, String propertyValue) in D:\Inetpub\Development3\index.cs:line 96 at ADSITest.Codebehind.Main.SetEmployeeID(String firstName, String lastName, Int32 employeeID) in D:\Inetpub\Development3\index.cs:line 39

    The exact line generating the exception is:

    de.Properties[propertyName][0] = propertyValue;

     

    I've found several examples online which reference this exact code.  Am I missing something?  What's the proper way to update an existing property?

     

    Thanks in advance!

    P.S. I'm using .NET 1.1

     

    Wednesday, March 29, 2006 2:35 PM

All replies

  • User-246688969 posted

    Changed from:

    de.Properties[propertyName][0] = propertyValue;

    to:

    de.Properties[propertyName].Value = propertyValue;

    Now everything works. [:D]

    Wednesday, March 29, 2006 3:32 PM
  • User1354132231 posted
    You found the solution before I could tell you why.  I tend to use the syntax, but for older versions of ADSI it is problematic because of a bug fix included with 1.1 and 1.0.  The problem surrounded the truncation of very large multi-valued attributes (like 'member').  To fix it, they put another flag on the underlying ADSI that said whether or not it supported 'cumulative' updates.  This meant that it would break older ADSI versions (unless they have later SP installed).  If you use the .Value consistently (and especially for single-valued attributes) you never run into this problem.  It is only updates using the direct index where this update mechanism gets triggered and starts to fall apart.

    Friday, March 31, 2006 4:07 PM