views:

166

answers:

1

hi,

Help plz! How can I make a webpart that has a button called "Create Site" and it programatically create a site (using my own custom template e.g. Mytemplate.STP) ?

The reason is of such task is, I dont want user to go into "Sites Action" -> create Site -> and then fill the whole form.

I want to give a user an easy interface with only title field, the rest i want to be done programatically.

Any other suggestions or work arounds are also appreciated.

Thank you

+1  A: 

to create a new sub website.

SPWeb web = [get the SPWeb object of site to create sub site from]
SPWebTemplate spWebTemplate = web.Site.GetWebTemplates(1033)["MyTemplateName#0"];
SPWeb spWebSite = web.Site.AllWebs.Add(newSiteUrl, "SiteName", "Site Description", 1033, spWebTemplate, false, false);

The "MyTemplateName" is the name of the SiteTemplate you created. #0 matches the Configuration ID of the specific configuration for that site template defined in the onet.xml of the template. – Hugo Migneron

Nat
The "MyTemplateName" is the name of the SiteTemplate you created. #0 matches the Configuration ID of the specific configuration for that site template defined in the onet.xml of the template.
Hugo Migneron