Search code examples
.netservermanager

Programmatically create Virtual Directory in Root of website


How can I programmatically (vb.net or C#) create a Virtual Directory in the Root of website in IIS7?

Using this link, it only shows you how to make one inside an application but I need it at the ROOT level of the website.


Solution

  • This worked on my machine (notice the indexes in second line):

    ServerManager iisManager = new ServerManager();
    Application app = iisManager.Sites[0].Applications[0];
    app.VirtualDirectories.Add("/VDir", "d:\\MyVDir");
    iisManager.Update();