ApplicationCollection.Add Method (String, String)

IIS 7.0

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

Namespace:   Microsoft.Web.Administration
Assembly:  Microsoft.Web.Administration (in Microsoft.Web.Administration.dll)

public Application Add(
	string path,
	string physicalPath


Type: System.String

The virtual path for the new application.

Type: System.String

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

Return Value

Type: Microsoft.Web.Administration.Application

A reference to the newly created Application object.

Exception Condition

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.

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.

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");
Return to top