Yoe have to use the System.DirectoryServices namespace classes (and peek at the IIS 
ADSI doc's) for this.
Following a little sample:

using System;
using System.DirectoryServices;
class IISVdir {
 public static void Main() {
  CreateVirtualDirectory("IIS://localhost/W3SVC/1/Root", "MyNewWeb", 
"c:\\someDirectoryPath");
 }

 public static void CreateVirtualDirectory(
      string parent,
      string virtDirectory,
      string physicalDir)
 {
  // Following flags taken from MSDN IIS Docs will generate warnings when compiling
  // Authorization flags
  const int  MD_AUTH_ANONYMOUS =  0x00000001; //Anonymous authentication available.
  const int  MD_AUTH_BASIC = 0x00000002; //Basic authentication available.
  const int  MD_AUTH_NT = 0x00000004; //Windows authentication schemes available.
 // Browse flags
  const int MD_DIRBROW_SHOW_DATE = 0x00000002; //Show date.
  const int MD_DIRBROW_SHOW_TIME = 0x00000004; // Show time.
  const int MD_DIRBROW_SHOW_SIZE = 0x00000008; //Show file size.
  const int MD_DIRBROW_SHOW_EXTENSION = 0x00000010; //Show file name extension.
  const int MD_DIRBROW_LONG_DATE = 0x00000020;  //Show full date.
  const int MD_DIRBROW_LOADDEFAULT = 0x40000000; // Load default page, if it exists.
  const uint MD_DIRBROW_ENABLED = 0x80000000;
 // Access Flags
  const int MD_ACCESS_READ = 0x00000001;  //Allow read access.
  const int MD_ACCESS_WRITE = 0x00000002;  //Allow write access.
  const int MD_ACCESS_EXECUTE = 0x00000004;  //Allow file execution (includes script 
permission).
  const int MD_ACCESS_SOURCE = 0x00000010;  //Allow source access.
  const int MD_ACCESS_SCRIPT = 0x00000200; // Allow script execution.
  const int MD_ACCESS_NO_REMOTE_WRITE = 0x00000400; // Local write access only.
  const int MD_ACCESS_NO_REMOTE_READ = 0x00001000; // Local read access only.
  const int MD_ACCESS_NO_REMOTE_EXECUTE = 0x00002000; // Local execution only.
  const int MD_ACCESS_NO_REMOTE_SCRIPT = 0x00004000; // Local host access only.

  string str = physicalDir;
        if (physicalDir.EndsWith("/") || physicalDir.EndsWith("\\"))
        {
          str = physicalDir.Remove(physicalDir.Length - 1, 1);
        }
        DirectoryEntry folderRoot = new DirectoryEntry(parent);
  folderRoot.RefreshCache();
        DirectoryEntry newVirDir;
        newVirDir = folderRoot.Children.Add(virtDirectory,"IIsWebVirtualDir");

        // Set Properties
  newVirDir.CommitChanges();
  newVirDir.Properties["Path"][0] = str;
  newVirDir.Properties["AuthFlags"][0] = MD_AUTH_ANONYMOUS | MD_AUTH_NT;
  newVirDir.Properties["EnableDefaultDoc"][0] = 1;
  newVirDir.Properties["DirBrowseFlags"][0] = MD_DIRBROW_SHOW_DATE | 
MD_DIRBROW_SHOW_TIME |
   MD_DIRBROW_SHOW_SIZE | MD_DIRBROW_SHOW_EXTENSION |
   MD_DIRBROW_LONG_DATE | MD_DIRBROW_LOADDEFAULT;
  newVirDir.Properties["AccessFlags"][0] = MD_ACCESS_READ |  MD_ACCESS_SCRIPT;
  newVirDir.CommitChanges();
  // Call AppCreat2 to create a Web application (0 =In-proc, 1 = Out-proc, 2 = Pooled)
  object[] appType = new object[]{0};
  newVirDir.Invoke("AppCreate2", appType);
        // Save Changes
        newVirDir.CommitChanges();
        folderRoot.CommitChanges();
        newVirDir.Close();
        folderRoot.Close();
    }
}


Willy.

----- Original Message -----
From: "Edward Ferron" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, April 18, 2002 9:42 PM
Subject: [DOTNET] IIS Managed Classes


> Are there any managed classes for IIS?  I would like to create virtual
> directories from my C# code using IIS.  I already know how to do it in COM
> using ADSI but I do not know how to perform the GetObject call in C# like I
> you would do in VB.
>
> How do you GetObject("IIS://servername/w3svc") in C#?
>
> How do you create a virtual directory in C# for IIS?
>
> Thanks,
>
> Eddie
>
> You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.
>

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to