Get list of virtual directories and locations?

Posted on 2007-07-19
Last Modified: 2013-11-07
How do I get the list of virtual directories and their locations on my computer programatically in .net?
Question by:kayhustle
    1 Comment
    LVL 8

    Accepted Solution

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



    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now