List IIS websites
Posted on 2008-10-14
I've got a small application that currently offers a list of virtual directories on the local instance of IIS. This has been fine for all users, until recently. One has now come along and said that he is not using an installation on localhost, but on a different website (same server, just not localhost).
I've got the following code that currently gives me a list of virtual directories...
DirectoryEntry iisServer = new DirectoryEntry("IIS://localhost/W3SVC/1");
DirectoryEntry folderRoot = iisServer.Children.Find("Root", IIsWebVirtualDir);
What I need is two things.
Firstly, I need something that will give me a list of all the local websites under IIS, and secondly, I need to change the above code to suit other websites. I did originally give the user a new version of the application with his website name hard-coded into the 'serverName' variable, but it didn't work. This was just a temporary workround, so I'm not too fussed that it worked, but the idea is that the user has a dropdown with websites in it, and when they select one, I populate the virtual directories dropdown. I've got most of this working. Just stuck on those 2 points.
I'd appreciate help with this.
Thanks in advance,