I am on Windows XP. We have Windows 2008 Servers. Need to run IIS Express until we get workstations or virtual machines with newer version of local O.S. for the real IIS 7.X.
Can I use DirectoryEntry to list my Sites and Virtual Directories when I run c# code under IIS Express? I have examples for setting up the Virtual Directories under IIS Express so that I think I have covered. Now I want to list them to ensure they exist.
Anyone know how to do this in C#? Just a small snippet of what I have been trying causes com exceptions...
DirectoryEntry iisServer = new DirectoryEntry("IIS://localhost/W3SVC/1");
DirectoryEntry folderRoot = iisServer.Children.Find("Root", "/");
var children = folderRoot.Children;
you can try something like this
void ListVirtualDirectories(string serverName, int siteId)
{
DirectoryEntry iisServer = new DirectoryEntry("IIS://" + serverName + "/W3SVC/" + siteId + "/ROOT");
foreach (DirectoryEntry webDir in iisServer.Children)
{
if (webDir.SchemaClassName.Equals("IIsWebVirtualDir"))
Console.WriteLine("Found virtual directory {0}", webDir.Name);
}
}