Solved

Create SharePoint Site Programmatically - Site Template Reverting to Blank

Posted on 2011-03-11
1
926 Views
Last Modified: 2012-05-11
Hi

I am programmatically trying to create a new site and apply the "Team Site" template.

If you do this through the SharePoint UI, the site is created with various lists in the template. However if I run the code sample below, a blank site is created - no lists, tasks etc.

It seems that the template is not being applied or I am specifying it incorrectly.

using (SPSite siteCollection = new SPSite("http://server/"))
{
   SPWebTemplateCollection templates = siteCollection.GetWebTemplates(1033);
   SPWebTemplate template = templates["STS#1"]; //Team Site

   using (SPWeb web = siteCollection.OpenWeb())
   {
      SPWeb newWeb = web.Webs.Add("TeamSite1", "This is a team site", "", 1033, template, false, false);
   }
}

Open in new window


Further code samples can be seen on MSDN.

Any help is much appreciated.
0
Comment
Question by:maaknplan
1 Comment
 
LVL 6

Accepted Solution

by:
psv1973 earned 500 total points
ID: 35110211
I tried the following whcih worked for me:

SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://server/));
SPSiteCollection sites = webApp.Sites;
SPSite Site = null;
Site = sites.Add("TeamSite1", "This is a teamsite","Description of the site", 1033, "STS#0"<br/>
               , "ownerLogin","ownerName", "ownerEmail");

A couple of differences. I'm creating the site at the site collection level. and I'm using adiffernt template name.

0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SharePoint Designer 2010 has tools and commands to do everything that can be done with web parts in the browser, and then some – except uploading a web part straight into a page that is edited in SPD. So, can it be done? Scenario For a recent pr…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question