这是我的代码,在2000试过成功.
================
string strSchema= "";
string strRootSubPath = "";
strSchema = "IIsWebVirtualDir";
strRootSubPath = "/W3SVC/1/Root";
DirectoryEntry deRoot= new DirectoryEntry("IIS://" + "YourServerName" + strRootSubPath); try
{
deRoot.RefreshCache();
DirectoryEntry deNewVDir = deRoot.Children.Add("AAA",strSchema);
deNewVDir.Properties["Path"].Insert(0,"C:\\Temp");
deNewVDir.CommitChanges();
deRoot.CommitChanges(); // Create a Application
if (strSchema == "IIsWebVirtualDir")
deNewVDir.Invoke("AppCreate",true); // Save Changes
deNewVDir.CommitChanges();
deRoot.CommitChanges();
deNewVDir.Close();
deRoot.Close();
lblStatus.Text = "Virtual Directory has been created"; }
catch (Exception ex)
{
lblStatus.Text = "Error: " + ex.Message;
}
================
string strSchema= "";
string strRootSubPath = "";
strSchema = "IIsWebVirtualDir";
strRootSubPath = "/W3SVC/1/Root";
DirectoryEntry deRoot= new DirectoryEntry("IIS://" + "YourServerName" + strRootSubPath); try
{
deRoot.RefreshCache();
DirectoryEntry deNewVDir = deRoot.Children.Add("AAA",strSchema);
deNewVDir.Properties["Path"].Insert(0,"C:\\Temp");
deNewVDir.CommitChanges();
deRoot.CommitChanges(); // Create a Application
if (strSchema == "IIsWebVirtualDir")
deNewVDir.Invoke("AppCreate",true); // Save Changes
deNewVDir.CommitChanges();
deRoot.CommitChanges();
deNewVDir.Close();
deRoot.Close();
lblStatus.Text = "Virtual Directory has been created"; }
catch (Exception ex)
{
lblStatus.Text = "Error: " + ex.Message;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货