Solved

Create SharePoint Site Programmatically - Site Template Reverting to Blank

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Work Over Net is a new and very powerful collaboration product. With its new easy interface it is becoming very competitive to other similar products like webex and office interactive. WON 2010 have the standard business tools needed for multi-offic…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

24 Experts available now in Live!

Get 1:1 Help Now