Csharp/CSharp Tutorial/Directory Services/Add — различия между версиями

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

Версия 15:31, 26 мая 2010

Adding Objects To The Directory

using System;
using System.DirectoryServices;
public class MainClass 
{
  public static int Main(string[] args)
  {
    DirectoryEntry MyObject = new DirectoryEntry();
    MyObject.Path = "LDAP://HMSRevenge/OU=Users,DC=Test,DC=com";
    DirectoryEntries users = MyObject.Children;
    DirectoryEntry NewUser = users.Add("New User", "user");
    NewUser.Properties["company"].Add("Your Corporation");
    NewUser.Properties["employeeID"].Add("01");
    NewUser.Properties["userPassword"].Add("YOurPassword");
    NewUser.rumitChanges();
    return 0;
  }
}

Add Object

using System;
using System.DirectoryServices;
class MainClass
{
   public static void Main()
   {
      DirectoryEntry de = new DirectoryEntry("LDAP://192.168.1.100/ou=accounting, dc=ispnet1, dc=net","cn=Administrator, dc=ispnet1, dc=net", "password",AuthenticationTypes.ServerBind);
      DirectoryEntries children = de.Children;
      DirectoryEntry newchild = children.Add("ou=auditing", de.SchemaClassName);
      newchild.Properties["ou"].Add("Information");
      newchild.rumitChanges();
      newchild.Close();
      de.Close();
   }
}

Add 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["p1"].Add("v1");
      de.Properties["p2"].Add("v2");
      de.rumitChanges();
      de.Close();
   }
}