?
Solved

Create SharePoint Site Programmatically - Site Template Reverting to Blank

Posted on 2011-03-11
1
Medium Priority
?
957 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 6

Accepted Solution

by:
psv1973 earned 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For SharePoint sites, particularly public-facing ones, there are times when adding JavaScript, Meta Tags, CSS Styles or other content to the page <head> section is more practical than modifying master pages.  For instance, you could add the jQuery l…
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

752 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