Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Add method (String, String, String, UInt32, String, Boolean, Boolean)

SPWebCollection.Add method (String, String, String, UInt32, String, Boolean, Boolean)

Creates a website with the specified site-relative URL, title, description, locale ID, and site definition or site template name.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public SPWeb Add(
	string strWebUrl,
	string strTitle,
	string strDescription,
	uint nLCID,
	string strWebTemplate,
	bool useUniquePermissions,
	bool bConvertIfThere


Type: System.String

A string that contains the new website URL relative to the root website in the site collection. For example, to create a website at http://MyServer/sites/MySiteCollection/MyNewWebsite, specify MyNewWebsite, or to create a website one level lower at http://MyServer/sites/MySiteCollection/Website/MyNewWebsite, specify Website/MyNewWebsite.

Type: System.String

A string that contains the title.

Type: System.String

A string that contains the description.

Type: System.UInt32

A 32-bit unsigned integer that specifies the locale ID.

Type: System.String

A string that contains the name of the site definition configuration or site template.

By default, a global site template (GLOBAL#0) is added to all site definitions. You cannot explicitly create a site based on a global site template.

Type: System.Boolean

true to create a subsite that does not inherit permissions from another site; otherwise, false .

Type: System.Boolean

true to convert an existing folder of the same name to a SharePoint site. false to throw an exception that indicates that a URL path with the specified site name already exists.

Return value

Type: Microsoft.SharePoint.SPWeb
An SPWeb object that represents the new website.

The following table shows the values for the default site definition configurations that are included in an installation of Microsoft SharePoint Foundation.


Site Definition


Team Site


Blank Site


Document Workspace


Basic Meeting Workspace


Blank Meeting Workspace


Decision Meeting Workspace


Social Meeting Workspace


Multipage Meeting Workspace




Basic Group Work Site


Blank Group Work Site



Note that WIKI provides a site definition configuration for legacy wiki sites that were originally created in an earlier version of SharePoint Foundation. Because standard site pages on SGS sites are wiki-enabled pages, you do not need to create sites that are specifically for wikis.

By default, a global site template (GLOBAL#0) is added to all site definitions. You cannot explicitly create a site based on it the global site template.

The following example is a console application that creates a new website as a child of another site and uses the Document Workspace template for the new site. After creating the new website, the application adds a link to it to the parent site's top link bar or, if the parent inherits links, to the top link bar for the root website in the collection.

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Navigation;

namespace ConsoleApp
    class Program
        static void Main(string[] args)
            using (SPSite site = new SPSite("http://localhost"))
                string parentWebName = "Team";

                using (SPWeb parentWeb = site.OpenWeb(parentWebName))
                    string webTitle = "Our Documents";
                    string webDesc = "A site created by a console application.";
                    string webName = "ourdocs";
                    string webUrl = String.Format("{0}/{1}", parentWebName, webName);
                    uint webLcid = parentWeb.Language;

                    // Name value for the Document Workspace template.
                    string webTemplateName = "STS#2";

                    SPWeb newWeb = null;

                    // Create the new web.
                        newWeb = site.AllWebs.Add(webUrl, webTitle, webDesc, webLcid, webTemplateName, false, false);
                    catch (ArgumentException ex)

                    // Add a link to the new web on the RootWeb's topnav bar.
                    if (newWeb != null)
                        // Set the new web's top link bar to inherit links from its parent web.
                        newWeb.Navigation.UseShared = true;

                        // Create a link pointing to the new web.
                        SPNavigationNode node = new SPNavigationNode(newWeb.Title, newWeb.ServerRelativeUrl);

                        // Find out if the parent inherits links.
                        bool parentInheritsTopNav = newWeb.ParentWeb.Navigation.UseShared;

                        if (parentInheritsTopNav)
                            // Add the link to the top link bar on the root web.
                            // Add the link to the top link bar on the parent web.

            Console.Write("\nPress ENTER to continue....");

© 2015 Microsoft