All About SharePoint

Liedong(Ken) Zheng,SharePoint Leader at SIMPLOT

Programmatically creating Sites from a Custom Web Template

Posted by ken zheng on November 15, 2010

In SharePoint 2010, you still can use

SPWeb newSite = web.Webs.Add(url, title, desc, LCID, templateName, true, false);

but the templateName is a string like ‘{Template-GUID}#TemplateName’.

I use below power shell script to get all templates

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

$url = "http://chidev51/sites/subsite"

$site= new-Object Microsoft.SharePoint.SPSite($url )
$loc= [System.Int32]::Parse(1033)
$templates= $site.GetWebTemplates($loc)

foreach ($child in $templates)
{
    write-host $child.Name "  " $child.Title
}
$site.Dispose()

 

Or in the code:

 // Get Web Template
    SPWebTemplateCollection webTemplates = site.RootWeb.GetAvailableWebTemplates(1033);
    SPWebTemplate webTemplate = (from SPWebTemplate t
                                 in webTemplates
                                 where t.Title == "test"
                                 select t).FirstOrDefault();
 webTemplate.Name

 

Here is a example that you can create site collection based on Custom Web Template

http://blog.mastykarz.nl/programmatically-creating-sites-site-collections-custom-web-template/

Advertisement

One Response to “Programmatically creating Sites from a Custom Web Template”

  1. MrutyunjayaRath said

    Give a full description I mean give step by step what have to and where have to go ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.