The following C# code example in uses the DirectoryEntry constructor to bind to an organization object and uses the Add method to create an organizationalUnit object in that organization.
using System;
using System.DirectoryServices;
namespace ADAM_Examples
{
class CreateOU
{
/// <summary>
/// Create ADAM Organizational Unit.
/// </summary>
[STAThread]
static void Main()
{
DirectoryEntry objADAM; // Binding object.
DirectoryEntry objOU; // Organizational unit.
string strDescription; // Description of OU.
string strOU; // Organiztional unit.
string strPath; // Binding path.
// Construct the binding string.
strPath = "LDAP://localhost:389/O=Fabrikam,C=US";
Console.WriteLine("Bind to: {0}", strPath);
// Get ADAM object.
try
{
objADAM = new DirectoryEntry(strPath);
objADAM.RefreshCache();
}
catch (Exception e)
{
Console.WriteLine("Error: Bind failed.");
Console.WriteLine(" {0}", e.Message);
return;
}
// Specify Organizational Unit.
strOU = "OU=TestOU";
strDescription = "ADAM Test Organizational Unit";
Console.WriteLine("Create: {0}", strOU);
The ADsPath string for the ADSI WinNT provider can be one of the following forms:
"WinNT:"
"WinNT://<domain name>"
"WinNT://<domain name>/<server>"
"WinNT://<domain name>/<path>"
"WinNT://<domain name>/<object name>"
"WinNT://<domain name>/<object name>,<object class>"
The domain name can be either a NETBIOS name or a DNS name.
The server is the name of a specific server within the domain.
The path is the path of on object, such as "printserver1/printer2".
The object name is the name of a specific object.
The object class is the class name of the named object. One example of this usage would be "WinNT://MyDomain/JeffSmith,user". Specifying a class name can improve the performance of the bind operation.