Solved

Create SharePoint Site Programmatically - Site Template Reverting to Blank

Posted on 2011-03-11
1
913 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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I have just recently built a new SharePoint 2007 farm on a complete Windows 2008 R2 server platform and part of my standard build procedure is to implement a warm up routine, usually in the form of a script that is scheduled every morning to launch …
I used to be SharePoint evangelist in our company, so my Outlook always full of questions about how to do this, or where I can find that. One day I found such an email with the following question: "how to attach 3-State workflow (one of the workflow…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now