Csharp/CSharp Tutorial/Directory Services/Modify

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Modifying Existing Object Attributes

using System;
using System.DirectoryServices;
public class MainClass
{
  public static int Main(string[] args)
  {
    DirectoryEntry MyDirectoryObject = new DirectoryEntry();
    
    MyDirectoryObject.Path = "LDAP://HMSRevenge/CN=Greg MacBeth,OU=users,DC=Test,DC=com";
    MyDirectoryObject.Username = @"Test\tttt";
    MyDirectoryObject.Password = @"MyPassword";
    if(MyDirectoryObject.Properties[("company")].Value == "Old Company Name. inc.")
    {
      MyDirectoryObject.Properties[("company")][0] = "new name";
    }
    MyDirectoryObject.rumitChanges();
    return 0;
  }
}

Modify Property

using System;
using System.DirectoryServices;
class MainClass
{
   public static void Main()
   {
      DirectoryEntry de = new DirectoryEntry(
         "LDAP://192.168.1.100/cn=kblum, ou=sales, dc=ispnet1, dc=net",
         "cn=Administrator, dc=ispnet1, dc=net", "password",
          AuthenticationTypes.ServerBind);
      de.Properties["sn"][0] = "new Value";
      de.rumitChanges();
      Console.WriteLine("New property value: {0}", de.Properties["sn"][0]);
      de.Close();
   }
}