# Enumerating WebSites and Virtual Directories

• ### Question

• I hope I have the appropraite forum...

I would like to be able to programatically enumerate the WebSites and/or Virtual Directories that are on a Server such that I can manage files within those directories.

Is there any way I can do this using .NET objects and/or methods.

If not are there any base Windows functions that I can call?
• Moved by Friday, May 1, 2009 3:20 PM (From:Building Development and Diagnostic Tools for .Net)
Friday, May 1, 2009 1:39 PM

### All replies

• You can use directory services:
```        private static void Echo()
{
using (DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3svc/1/ROOT")) {
foreach (DirectoryEntry child in root.Children) {
Console.WriteLine(child.Name);
}
}
}```
Friday, May 1, 2009 2:43 PM
• Thank You

Almost there,

Once i hae the DirectoryEntry for the WebSite and/or Virtual directory,  Is there any way to determine the local path for the Virtual Directory  i.e.  [C:\inetpub\wwwroot\MyWebApp,   or C:\Program Files\MyCompany\MyWebApp ]?
Friday, May 1, 2009 4:52 PM
• It's the name and the path property if the key is IIsWebVirtualDir - you can find more details here : http://msdn.microsoft.com/en-us/library/ms525389.aspx.

```        private static void Echo()
{
using (DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3svc/1/ROOT")) {
foreach (DirectoryEntry child in root.Children) {
Console.WriteLine("\n\n{0}", child.Name);

foreach (PropertyValueCollection pc in child.Properties) {
Console.Write("{0} : ", pc.PropertyName);
foreach (object v in pc) {
Console.Write("{0},", v);
}
Console.WriteLine();
}
}
}
}```

HTH
Friday, May 1, 2009 6:18 PM