I  find spawning mkwebdir.vbs (see C:\inetpub\adminscripts) easy.

Dominic 


-----Original Message-----
From: Moderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Rob MacFadyen
Sent: Monday, 13 October 2003 8:51 AM
To: [EMAIL PROTECTED]

Jesse,

You can create virtual directories programmatically. You need to use ADSI...
and can do either with VBScript or directly from C#.

Here's an old chunk of code that creates a virtual directory:
/// <summary>
/// Create a virtual directory
/// </summary>
/// <param name="WebSite">1 for the default website, 2 etc for non-default
web sites</param> /// <param name="VDirName">Name of directory to
create</param> /// <param name="Path">File system path for directory</param>
/// <param name="RootDir">Create a root level directory or actual virtual
directory</param> private void CreateVDir(string WebSite, string VDirName,
string Path, bool
RootDir)
{
    System.DirectoryServices.DirectoryEntry IISSchema;
    System.DirectoryServices.DirectoryEntry IISAdmin;
    System.DirectoryServices.DirectoryEntry VDir;
    bool IISUnderNT;

    //
    // Determine rough version of IIS
    //
    IISSchema = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/Schema/AppIsolated"
);
    if (IISSchema.Properties["Syntax"].Value.ToString().ToUpper() ==
"BOOLEAN")
        IISUnderNT = true;
    else
        IISUnderNT = false;
    IISSchema.Dispose();

    //
    // Get the admin object
    //
    IISAdmin = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/" + WebSite +
"/Root");

    //
    // If we're not creating a root directory
    //
    if (!RootDir)
    {
        //
        // If the virtual directory already exists then delete it
        //
        foreach(System.DirectoryServices.DirectoryEntry v in
IISAdmin.Children)
        {
            if (v.Name == VDirName)
            {
                //
                // Delete the specified virtual directory if it already
exists
                //
                IISAdmin.Invoke("Delete", new string [] { v.SchemaClassName,
VDirName });
                IISAdmin.CommitChanges();
            }
        }
    }

    //
    // Create the virtual directory
    //
    if (!RootDir)
    {
        VDir = IISAdmin.Children.Add(VDirName, "IIsWebVirtualDir");
    }
    else
    {
        VDir = IISAdmin;
    }

    //
    // Setup the VDir
    //
    VDir.Properties["AccessRead"][0] = true;
    VDir.Properties["AccessExecute"][0] = true;
    VDir.Properties["AccessWrite"][0] = false;
    VDir.Properties["AccessScript"][0] = true;
    VDir.Properties["AuthNTLM"][0] = false;
    VDir.Properties["EnableDefaultDoc"][0] = true;
    VDir.Properties["EnableDirBrowsing"][0] = false;
    VDir.Properties["DefaultDoc"][0] = true;
    VDir.Properties["Path"][0] = Path;

    //
    // NT doesn't support this property
    //
    if (!IISUnderNT)
    {
        VDir.Properties["AspEnableParentPaths"][0] = true;
    }

    //
    // Set the changes in stone
    //
    VDir.CommitChanges();

    //
    // Make it a web application
    //
    if (IISUnderNT)
    {
        VDir.Invoke("AppCreate", false);
    }
    else
    {
        VDir.Invoke("AppCreate2", 1);
    }
}


Regards,

Rob
--
RMTrack a great bug tracking tool! Fully customizable, automated workflow,
e-mail notification, import utility, and much much more.
Setup a demo at www.rmtrack.com (version 1.2.2 now available!)

===================================
This list is hosted by DevelopMentor.  http://www.develop.com NEW! ASP.NET
courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
NEW! ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to