假如虚拟目录名为”chinabs”,先在项目中引用
system.directoryservices.dll,再
using system.directoryservices;
protected system.directoryservices.directoryentry dirroot;
1、添加新的虚拟目录
directoryentry newvirdir = dirroot.children.add(“chinabs”,”iiswebvirtualdir”);
newvirdir.invoke(“appcreate”,true);
newvirdir.commitchanges();
dirroot.commitchanges();
2、更改虚拟目录属性
//虚拟目录的属性较常用的有:accessread,accesswrite,accessexecute,accessscript,defaultdoc,enabledefaultdoc,path等
directoryentry dirport = dirroot.children.find(“chinabs”,”iisvirtualdir”);
dirport .properties[“accessread”][0] = true;
3、删除虚拟目录
directoryentry dirport = dirroot.children.find(“chinabs”,”iisvirtualdir”);
dirport.invoke(“appdelete”,true);
dirroot.commitchanges();
或者:
object[] part = new object[2];
part[0] = “iiswebvirtualdir”;
part[1] = “chinabs”;
dirroot.invoke(“delete”,part);
dirroot.commitchanges();