System.DirectoryServices.DirectoryEntry iISAdmin = new System.DirectoryServices.DirectoryEntry("IIS://" + sWebSite + "/W3SVC/1/Root");
string sWebPath = iISAdmin.Properties["Path"].Value.ToString();
//If the virtual directory already exists then delete it
foreach(System.DirectoryServices.DirectoryEntry vd in iISAdmin.Children)
{
if(vd.Name==sAppName)
{
sWebPath += "\\" + vd.Name;
if(vd.KeyType == "IIsWebVirtualDir")
sWebPath=vd.Properties["Path"].Value.ToString();
iISAdmin.Invoke("Delete", new string[]{vd.SchemaClassName, sAppName});
System.IO.Directory.Delete(sWebPath);
iISAdmin.CommitChanges();
break;
}
}
Bookmarks