I’m building a MOSS/InfoPath demo and a part of the demo I need to create a site based on a customized template. Here’s the V.Net code to create the site:

Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Utilities

Dim newSite As New SPSite(“http://server/siteurl”)
Dim newWeb As SPWeb = newSite.OpenWeb()
newWeb.AllowUnsafeUpdates = True
newWeb.Update()
Dim subsites As SPWebCollection = newWeb.Webs
Dim newSubWeb As SPWeb = subsites.Add(“site_url”, “site_title”, “site_description”, 1033, “template.stp”, True, False)

To use a default template, refer to Todd Baginski’s blog, he has a list of what to write in the template section. This information is also available in C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATE1033XMLWEBTEMP.XML – it follows the structure of “Template Name#Configuration ID” so Team Site is “STS#0” instead of “template.stp”.

Want more information refer to MSDN Using Disposable Windows SharePoint Services Objects.

Advertisements