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
MrutyunjayaRath said
Give a full description I mean give step by step what have to and where have to go ?