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?
LVL 1
kayhustleAsked:
Who is Participating?
 
sabeeshCommented:
This would be helpful

http://www.dotnetjunkies.com/WebLog/razor/archive/2004/12/15/37118.aspx

private DirectoryEntry iisServer;

public DirectoryEntries GetVirtualDirectories()

{

try

{

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 + ")");

}

0
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.