One Way To Enumerate Virtual Directories On The Local Machine
I had a need to list the IIS directories available on my local machine, along with their local paths. There is a lot of cool WMI stuff to support things like this for IIS 6, but since I'm using XP I can't use it. I found it to be quite challenging to find code for this on the Web, so here's the code in case anyone else runs across the same challenge in the future:
using DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC/1/Root")
foreach (DirectoryEntry child in root.Children)
{
if (child.SchemaClassName == "IIsWebVirtualDir")
{
Console.WriteLine(string.Format("{0}: {1}", child.Name, child.Properties["Path"][0]));
}
}
Let me know if there are better ways to do this.