locked
add values to multiple-valued attribute error RRS feed

  • Question

  • User-737517480 posted
    try add multiple values to a mulitple-valued attribute (that can be done with a GUI / LDIF).
    However, use following code, I get error when insert multiple values for Properties("mgrpRFC822MailMember") (but it works with only one entry)
    Any help is very welcome.
    Thx

     Dim de1 = New DirectoryEntry("LDAP://" & ldapServerName & _
                "/ou=MailGroup,dc=pcihl,dc=com", "cn=Manager,dc=pcihl,dc=com", "secret", AuthenticationTypes.ServerBind)
                Dim newLstEntry As DirectoryEntry = de1.Children.Add("cn=List_RD", "mailGroup")
                newLstEntry.Properties("cn").Add("List_RD")
                newLstEntry.Properties("mailHost").Add("test.pcihl.com")
                newLstEntry.Properties("mail").Add("list_RD@test.pcihl.com")
                newLstEntry.Properties("mgrpAllowedDomain").Add("test.pcihl.com")
                newLstEntry.Properties("mgrpRFC822MailMember").Add("testuers1@test.pcihl.com")
                newLstEntry.Properties("mgrpRFC822MailMember").Add("testuers2@test.pcihl.com")  
                newLstEntry.CommitChanges()

    Friday, May 26, 2006 1:59 AM

All replies

  • User479513661 posted

    The attribute existed after you insert first,if you want to replace the value of the attribute.

    you must check whether the value exists.

    iI am'not  familiar with vb.net,

     Forgiving me  coding with c#,

    hope this helps

     

    static void SetProperty(DirectoryEntry de, string PropertyName, string PropertyValue)
      {
       if (PropertyValue != null)
       {
        if (de.Properties.Contains(PropertyName))
        {
         de.Properties[PropertyName][0] = PropertyValue;
        }
        else
        {
         de.Properties[PropertyName].Add(PropertyValue);
        }
       }
      }

    Friday, May 26, 2006 4:17 AM
  • User-737517480 posted

    The attribute existed after you insert first,if you want to replace the value of the attribute.

    you must check whether the value exists.

    iI am'not  familiar with vb.net,

     Forgiving me  coding with c#,

    hope this helps

     

    static void SetProperty(DirectoryEntry de, string PropertyName, string PropertyValue)
      {
       if (PropertyValue != null)
       {
        if (de.Properties.Contains(PropertyName))
        {
         de.Properties[PropertyName][0] = PropertyValue;
        }
        else
        {
         de.Properties[PropertyName].Add(PropertyValue);
        }
       }
      }



    sorry, what is the difference between
      de.Properties[PropertyName][0] = PropertyValue;
     and
       de.Properties[PropertyName].Add(PropertyValue);
    Friday, May 26, 2006 5:25 AM
  • User479513661 posted

    if you have set the value of "X" attribute,and want to replace the value of the attribute,you can code this: 

    de.Properties["X"][0] = PropertyValue.

     

    And if the "X" attribute doesn't exist,you should write:

    de.Properties["X"].Add(PropertyValue);

     

    Friday, May 26, 2006 10:03 AM
  • User-737517480 posted

    if you have set the value of "X" attribute,and want to replace the value of the attribute,you can code this: 

    de.Properties["X"][0] = PropertyValue.

     

    And if the "X" attribute doesn't exist,you should write:

    de.Properties["X"].Add(PropertyValue);

     


    but if i want to add multiple value (the the attribute existing).  Then, I should use sth like?

    de.Properties["X"][1] = PropertyValue.?


    Sunday, May 28, 2006 8:53 PM
  • User479513661 posted

    only use

    de.Properties["propertyName"].Add("values")

     

    If it throw a exception ,the property  you want to set  maybe is not   multiple-value  property

    Could you tell what is the property name?

    you can try some mutiple-value property and set  some values

    For example:  url,otherTelephone,otherHomePhone

    they are a set of mutiple-value property of users

     

    Regrads......

     

    Tuesday, May 30, 2006 8:31 PM
  • User-737517480 posted

    Thx stswordman for your response.

    however, i think it should be a multiple-value property (as I can add it through a GUI).

    anyway, the attribute is

    attributetype ( 2.16.840.1.113730.3.1.30
          NAME 'mgrpRFC822MailMember'
          DESC 'RFC822 mail address of email only member of group'
          EQUALITY caseIgnoreIA5Match
          SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{256} )

    Any idea?

    only use

    de.Properties["propertyName"].Add("values")

     

    If it throw a exception ,the property  you want to set  maybe is not   multiple-value  property

    Could you tell what is the property name?

    you can try some mutiple-value property and set  some values

    For example:  url,otherTelephone,otherHomePhone

    they are a set of mutiple-value property of users

     

    Regrads......

     

    Wednesday, May 31, 2006 11:06 PM