Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADSI Problem HELP

Status
Not open for further replies.

chevoldavis

Programmer
Joined
Mar 6, 2005
Messages
3
Location
US
Here is the problem I want to create web directories from a webpage. Here is the code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.DirectoryServices;
using System.IO;
//Add reference to DirectoryServices
public class SetupUtility

{

public SetupUtility()
{
}
public int CreateWebSite(string webSiteName, string pathToRoot)
{
return CreateWebSite(webSiteName, pathToRoot, false);
}
public int CreateWebSite(string webSiteName, string pathToRoot, bool createDir)
{
System.DirectoryServices.DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC");
// Searches IIS and finds an unused ID value for new web site
int siteID = 1;
foreach(DirectoryEntry e in root.Children)
{
if(e.SchemaClassName == "IIsWebServer")
{
int ID = Convert.ToInt32(e.Name);
if(ID >= siteID)
{
siteID = ID+1;
}
}
}

// Create the web site and set some default options
DirectoryEntry site = (DirectoryEntry)root.Invoke("Create", "IIsWebServer", siteID);
site.Invoke("Put", "ServerComment", webSiteName);
site.Invoke("Put", "KeyType", "IIsWebServer");
site.Invoke("Put", "ServerBindings", ":80:");
site.Invoke("Put", "ServerState", 2);
site.Invoke("Put", "FrontPageWeb", 1);
site.Invoke("Put", "DefaultDoc", "Default.aspx");
site.Invoke("Put", "SecureBindings", ":443:");
site.Invoke("Put", "ServerAutoStart", 1);
site.Invoke("Put", "ServerSize", 1);
site.Invoke("SetInfo");
// Create application virtual directory and set options
DirectoryEntry siteVDir = site.Children.Add("Root", "IISWebVirtualDir");
siteVDir.Properties["Path"][0] = pathToRoot;
siteVDir.Properties["AccessScript"][0] = true;
siteVDir.CommitChanges();
siteVDir.Properties["AppFriendlyName"][0] = "Default Application";
siteVDir.Invoke("AppCreate3", new object[] {2, "DefaultAppPool", true});
siteVDir.CommitChanges();
return siteID;
}
}

I am calling it like so:
SetupUtility su = new SetupUtility ();
su.CreateWebSite(TextBox1.Text, "C:\\inetpub\\ + TextBox1.Text, true);
System.IO.Directory.CreateDirectory("C:\\inetpub\\ + TextBox1.Text);
OurLabel.Text += "Virtual Directory for " + TextBox1.Text + " was created" + "<br>";


It creates a new virtual Directory not under the Default WebSite. I want it to put it under the Default WebSite not on its own directory, how can I do this??
 
Isn't it this bit of code that creates a new site?

DirectoryEntry site = (DirectoryEntry)root.Invoke("Create", "IIsWebServer", siteID);
site.Invoke("Put", "ServerComment", webSiteName);
site.Invoke("Put", "KeyType", "IIsWebServer");
site.Invoke("Put", "ServerBindings", ":80:");
site.Invoke("Put", "ServerState", 2);
site.Invoke("Put", "FrontPageWeb", 1);
site.Invoke("Put", "DefaultDoc", "Default.aspx");
site.Invoke("Put", "SecureBindings", ":443:");
site.Invoke("Put", "ServerAutoStart", 1);
site.Invoke("Put", "ServerSize", 1);


And then silence smacks right in there...
... And it is loud!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top