Learning SharePoint   Enhance Your SharePoint Knowledge

Subscribe to Learning SharePoint Subscribe
Twitter Learning SharePointFollow Us
in Learning SharePoint
Check Out Our New SharePoint 2013 series!

Programatically create Site from Site Template Sharepoint 2010

07/25/2010  
Category: SharePoint 2010


Here is a code snippet to create a site from an existing site template in sharepoint 2010.
Please Note that siteUrl below contains the URL for the site collection, for example, Site_Name or sites/Site_Name. It may either be server-relative or absolute for typical sites.

protected void CreateTeamSite(string siteUrl, string newsiteName, SPFieldUserValue siteOwner)
{
try
{
using (SPSite site = new SPSite(“http://SPSite”))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;

// Set the user for your new site
string ownerLogin = siteOwner.User.LoginName; //user’s login name
string ownerEmail = siteOwner.User.Email;
string ownerName = siteOwner.User.Name;

//Create new web site
SPWeb newWeb = siteCollection.Add(“/” + siteUrl, siteName, “site description”, 1033,{Name of the Site Template}, ownerLogin,ownerName,ownerEmail );
newWeb.Update();
}
}
}

To get Name of the existing site template {Name of the Site Template} follow the below steps

1. Save a Site as a Template.

2. Go to Site settings –> sites & workspaces –> create.

3. IE Tools > Developer Tools > Find > Select Element By Click > View > Source > DOM (Element) > Highlight and copy the section
<OPTION value=”{D120C236-16AC-49D0-2278-F2283F0FD521}#sitename”>test</OPTION> . The one in bold will be your site template name.

Subscribe to Learning SharePoint Subscribe
Twitter Learning SharePointFollow Us
in Learning SharePoint
Advertisement

Random Posts

Bcs Powershell commands Sharepoint 2010
Bcs Powershell commands Sharepoint»

New-SPBusinessDataCatalogServiceApplication – Creates a new Business Data Connectivity service application in the farm. New-SPBusinessDataCatalogServiceApplication -ApplicationPool [-AssignmentCollection ] [-Confirm []] [-DatabaseCredentials»

Programming with dialog in Sharepoint 2010
Programming with dialog in»

Related Post : Passing parameters to the dialog sharepoint 2010 Client Object model Beyond working with notifications and status bars,»

Impersonation in Sharepoint designer 2010 workflow
Impersonation in Sharepoint designer»

As you might know that for security reasons, a SharePoint designer workflow always runs under the permissions of the user»

Recent Forum Posts

Linq to Sharepoint

by RS on May 18, 2012

comments on the code

by spbsmile on May 18, 2012

connection(add) EditControlBlock and my program

by spbsmile on May 18, 2012

Custom master pages used in multiple SharePoint 2010 sites

by ubersteve on May 18, 2012

upload file and click on button but cant upload file into list by using below code

by santhoshreddy on May 18, 2012