VirtualDirectoryCollection.Add(String, String) Method

Definition

Creates a new virtual directory by using the specified parameters and adds it to the virtual directory collection.

public:
 Microsoft::Web::Administration::VirtualDirectory ^ Add(System::String ^ path, System::String ^ physicalPath);
public Microsoft.Web.Administration.VirtualDirectory Add (string path, string physicalPath);
override this.Add : string * string -> Microsoft.Web.Administration.VirtualDirectory
Public Function Add (path As String, physicalPath As String) As VirtualDirectory

Parameters

path
String

The path to the virtual directory, relative to the application that will host the virtual directory.

physicalPath
String

The physical location where the contents of the virtual directory are stored.

Returns

A reference to the newly created VirtualDirectory object.

Exceptions

The path is null, a zero-length string, or contains characters returned by the InvalidVirtualDirectoryPathCharacters() method.

The path specified by the path parameter already exists in the virtual directory..

Examples

The following example uses the Add method to create a new virtual directory in an application.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Web.Administration;
using Microsoft.Web.Management;

namespace AdministrationSnippets
{
    class AdministrationVirtualDirectoryCollectionItem2
    {
        public void VirtualDirectoryAddGet()
        {
            ServerManager manager = new ServerManager();
            Site defaultSite = manager.Sites["Default Web Site"];

            ApplicationPool blogPool = manager.ApplicationPools.Add("PhotoApplicationPool");
            Application app = defaultSite.Applications.Add("/photo", @"C:\inetpub\wwwroot\photo");
            app.VirtualDirectories.Add("/family", @"C:\photos\family");
            manager.CommitChanges();
        }
    }
}

Remarks

This method creates a VirtualDirectory object and adds it to the virtual directory collection in memory. However, to commit the virtual directory configuration to the configuration system, you will need to use the ServerManager class to perform an update. The instance returned from this call does not reflect the default application values specified in the VirtualDirectoryDefaults property of the current Application object.

Applies to