Creating a SharePoint Sub Site from Custom Template Through Code

This blog explains the steps involving creating a Sharepoint subsite from a custom template by calling Sharepoint web service from .Net code.

Sharepoint Meeting Webservice has a method named CreateWorkspace that allows the creation of subsite on the specified Sharepoint server. The URL for meeting web service is http:///_vti_bin/Meetings.asmx where can even be a subsite location. The syntax for the Create workspace method is

CreateWorkspace(title, templateName, lcid, timeZoneInformation)
Title is the title for the new sub site that will be created.
TemplateName is the name of the template based on which the
new sub site will be created.
LCID is the locale identifier
timeZoneInformation is the time zone information for the new sub site.

All the arguments mentioned above are pretty straightforward except for the template name. For creating subsites based on the default Sharepoint templates we need to pass the template id such as “MPS#”.Whereas for creating based on custom templates we need to pass the template file name as the argument such as “Mytemplate.stp”

To have a preview of the built-in site templates click here. To find out the templates ids click.

Typical code for creating subsite custom template is shown below

Samples.SP.TimeZoneInf tz = new Samples.SP.TimeZoneInf();
SP.Meetings meetings = new SP.Meetings();
meetings.Url = “http://sitename/_vti_bin/meetings.asmx”;
meetings.Credentials = new System.Net.NetworkCredential(“user name”, “password”, “domain”);
meetings.CreateWorkspace(“Site title”, “Mytemplate.stp”, 1033,tz);