开发者

Programmatically creating site using custom template

How can I make a webpart that has a button called "Create Site" and it programmatically create a site (using my own custom template e.g. Mytemplate.STP)开发者_开发百科 ?

The reason is of such task is, I don't 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 programmatically.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜