create a function to create a new virtual directory and set some properties of the new virtual directory.
public void CreateNewVirtualDirectory(int ServerId, string VirtualDirName, string Path, bool AccessScript)
{
DirectoryEntry Parent = new DirectoryEntry(@"IIS://localhost/W3SVC/" + ServerId.ToString() + "/Root");
DirectoryEntry NewVirtualDir;
NewVirtualDir = Parent.Children.Add(VirtualDirName, "IIsWebVirtualDir");
NewVirtualDir.Properties["Path"][0] = Path;
NewVirtualDir.Properties["AccessScript"][0] = AccessScript;NewVirtualDir.CommitChanges();
}
You can call this function like
CreateNewVirtualDirectory(1, "MyNewVirtualDirectory", @"C:\Inetpub\wwwroot\MyDir", true)
create a function to Delete virtual directory .
public void DeleteVirtualDirectory(int ServerId, string VirtualDirName)
{
DirectoryEntry Parent = new DirectoryEntry(@"IIS://localhost/W3SVC/" + ServerId.ToString() + "/Root");
Object[] Parameters = {"IIsWebVirtualDir",VirtualDirName};
Parent.Invoke("Delete",Parameters );
}
How to open a new window with JavaScript
16 years ago