locked
Error using clear() Metod RRS feed

  • Question

  • User-2079623988 posted

    Error: CS0117: System.DirectoryServices.PropertyValueCollection does not have definition for clear.

    The code works fine if I /* the "user.Properties["postalcode"].clear();" part.

    Code:

    void btnSubmit_Click(object sender, System.EventArgs e)
    {
     string adPath = "
    LDAP://mycompany";
            string sFilter = String.Format(
     "(&(objectClass=user)(objectCategory=person)(sAMAccountName={0}))", User.Identity.Name.Split(new char[]{'\\'})[1]);
            string[] attribs = new string[]{"postalCode"};
            DirectoryEntry de = new DirectoryEntry(adPath);
            de.AuthenticationType = AuthenticationTypes.Secure;
            DirectorySearcher ds = new DirectorySearcher( de, sFilter, attribs);
           
      SearchResult sr = ds.FindOne();
      string postcode= tbText.Text;
      lblText.Text = postcode;
     using (DirectoryEntry user = sr.GetDirectoryEntry()
    {
      if (sr != null)
      {
          if(kalle != "")
          {
              if (user.Properties.Contains("postalcode"))
                  {
                     user.Properties["postalcode"].Value = postcode;
                  }
                   else
                  {
                     user.Properties["postalcode"].Add(12345);
                  }
           }
       
          else
          {
              user.Properties["postalcode"].clear(); //error here
          }       
           user.CommitChanges(); 
      }  
     }      
    }

    Namespace is:

    <%@ import Namespace="System.DirectoryServices" %>
    <%@ import Namespace="System" %>
    <%@ import Namespace="System.Collections.Generic" %>
    <%@ import Namespace="System.Collections.ObjectModel" %>


    Or does anyone else have another solution instead of clear() Method to reset attribut in AD. 

    Thx Bruno 

    Friday, May 5, 2006 9:59 AM

All replies

  • User1354132231 posted
    Did you try .Clear()?  C# is case-sensitive.
    Friday, May 5, 2006 11:39 AM
  • User-2079623988 posted

    Thanks  !!!

    Monday, May 8, 2006 2:13 AM