Share via


ApplicationCollection.Add(String, String) Method

Definition

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

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

Parameters

path
String

The virtual path for the new application.

physicalPath
String

The physical location where the contents of the application are stored.

Returns

A reference to the newly created Application object.

Exceptions

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

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

Examples

The following example creates an application and commits the changes to the configuration system by using the ServerManager object.

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

namespace AdministrationSnippets
{
    public class AdministrationApplicationCollectionAdd
    {
        // Creates a new application and udpates the site manager.
        public void AddApplication()
        {
            ServerManager manager = new ServerManager();
            Site defaultSite = manager.Sites["Default Web Site"];

            ApplicationPool blogPool = manager.ApplicationPools.Add("BlogApplicationPool");
            Application app = defaultSite.Applications.Add("/blogs", @"C:\inetpub\wwwroot\blogs");
            manager.CommitChanges();
        }
    }
}

Remarks

This method creates an Application object and adds it to the ApplicationCollection object in memory. However, to commit the application 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 ApplicationDefaults property of the Site object.

Applies to