Solved

Create SharePoint Site Programmatically - Site Template Reverting to Blank

Posted on 2011-03-11
1
931 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Pimping Sharepoint 2007 without Server-Side Code Part 1 One of my biggest frustrations with Sharepoint 2007 in the corporate world is that while good-intentioned managers lock down the more interesting capabilities of Sharepoint programming in…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

791 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