1

I would like to know if it possible to create a virtual directory in C# directly to a site instead of creating a web application and then linking a virtual directory to that. I am using iis 7. thanks ! Src:http://blogs.msdn.com/b/carlosag/archive/2006/04/17/microsoftwebadministration.aspx

1
  • This should be moved to stack overflow. Commented Nov 7, 2011 at 13:15

3 Answers 3

1

You can do this in PowerShell.

From Learn IIS

PS IIS:\> New-Item 'IIS:\Sites\Default Web Site\DemoVirtualDir1' -type VirtualDirectory -physicalPath c:\test\virtualDirectory1
Sign up to request clarification or add additional context in comments.

3 Comments

Did you read the answer? I provided a PowerShell line that will do it. If you want it in a different language, then ask for it specifically. I'm not a mind reader.
I am sorry for that. I would like to have it in C#
Then this belongs on StackOverflow.
0

you can do this in c#. worked for me.

using (ServerManager srv = new ServerManager())
{
    var site = srv.Sites.FirstOrDefault(c => c.Name == siteName);
    var app = site.Applications.Add("/SubDirecory1/SubDirectory2", acbphysicalPath.Text +  @"\SubDirectory1\SubDirectory2");
    app.ApplicationPoolName = txtAppPool.Text;
    srv.CommitChanges();
}   

Comments

0

Using Microsoft.Web.Administration you can do:

ServerManager iisManager = new ServerManager();
Application app = iisManager.Sites[“NewSite”].Applications[“/Sales”];
app.VirtualDirectories.Add(“/VDir”, “d:\\MyVDir”);
iisManager.CommitChanges();

Read more on it here:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.