//假如虛擬目錄名為"Webtest",先在項目中引用
//System.DirectoryServices.dll,再
using System.DirectoryServices;
protected System.DirectoryServices.DirectoryEntry dirroot;
1、添加新的虛擬目錄
DirectoryEntry newVirDir = dirroot.Children.Add("Webtest","IISWebVirtualDir");
newVirDir.Invoke("AppCreate",true);
newVirDir.CommitChanges();
dirroot.CommitChanges();
2、更改虛擬目錄屬性
//虛擬目錄的屬性較常用的有:AccessRead,AccessWrite,AccessExecute,AccessScript,DefaultDoc,EnableDefaultDoc,Path等
DirectoryEntry Dirport = dirroot.Children.Find("Webtest","IISVirtualDir");
Dirport .PropertIEs["AccessRead"][0] = true;
3、刪除虛擬目錄
DirectoryEntry Dirport = dirroot.Children.Find("Webtest","IISVirtualDir");
Dirport.Invoke("AppDelete",true);
dirroot.CommitChanges();
或者:
object[] part = new object[2];
part[0] = "IISWebVirtualDir";
part[1] = "Webtest";
dirroot.Invoke("Delete",part);
dirroot.CommitChanges();