Get list of virtual directories and locations?

How do I get the list of virtual directories and their locations on my computer programatically in .net?
Who is Participating?
This would be helpful

private DirectoryEntry iisServer;

public DirectoryEntries GetVirtualDirectories()




string serverName = "localhost";

string VirDirSchemaName = "IIsWebVirtualDir";

iisServer = new DirectoryEntry("IIS://" + serverName + "/W3SVC/1");

DirectoryEntry folderRoot = iisServer.Children.Find("Root",VirDirSchemaName);

return folderRoot.Children;


catch (Exception e)


throw new Exception("Error while retrieving virtual directories.",e);



When you get the DirectoryEntries object back from the GetVirtualDirectories() method you can go through the collection with a normal foreach.

DirectoryEntries entries = GetVirtualDirectories();

foreach(DirectoryEntry d in entries)


listBox1.Items.Add(d.Name + "(" + d.Path + ")");


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.