The following method will create a new IIS Virtual Folder object, based on a path and a friendly name.
ServerID is the ID of the “Web Site” you want to work with in IIS.
VirtualDirName is the name of the Folder that will be available through IIS (eg. http://localhost/VirtualDirName)
Path is the physical location of the folder on the disk.
AppPool is the name of the application pool that your new folder will run under.
AccessScript is a boolean value to determine whther the folder will be allowed to access scripts
CreatePhysicalFolder is a boolean to tell the method whether it should create non-existent file system folders.
public static bool CreateNewVirtualDirectory(int ServerId, string VirtualDirName, string Path, _ string AppPool, bool AccessScript, bool CreatePhysicalFolder) { DirectoryEntry Parent = new DirectoryEntry(@"IIS://localhost/W3SVC/" + ServerId.ToString() + "/Root"); DirectoryEntry NewVirtualDir; NewVirtualDir = Parent.Children.Add(VirtualDirName, "IIsWebVirtualDir"); NewVirtualDir.Properties["Path"][ 0] = Path; New if(!Directory.Exists(Path)) { Directory.CreateDirectory(Path); return true; } } else { return true; } return true; }