Wednesday, February 20, 2008

Enumerate IIS Virtual Directories

private void LoadIISInformation()
{
Dictionary entries = new Dictionary();
foreach (DirectoryEntry dir in VirtualDirectories)
{
entries[dir.Name] = dir;
this.listWebsitesComboBox.Items.Add(dir.Name);
}
this.listWebsitesComboBox.Tag = entries;
}

public DirectoryEntries VirtualDirectories
{
get
{
try
{
return (new DirectoryEntry("IIS://localhost/W3SVC/1")).Children.Find("Root", "IIsWebVirtualDir").Children;
}
catch (Exception e)
{
throw new Exception("Error while retrieving virtual directories.", e);
}
}
}


Probably you are interested about physical path of the virtual directories as I was. It is pretty simple, there is a property named "path" which will provide the physical path of your virtual directory.

1 comment:

Please, no abusive word, no spam.