If we want to create a site in our site collection programmatically, so here is the code for it. I have created a console application, you can use it according to your convenience wherever required say Feature Receiver or Event handler
Code snippet
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite objSite = new SPSite("SiteUrl"))
{
using (SPWeb objWeb = objSite.OpenWeb())
{
objWeb.AllowUnsafeUpdates = true;
SPWebCollection objWebColl = objWeb.Webs;
objWebColl.Add("MyTestSite", "TestSite", "this is a test Site", 1033,
"STS#0", true, false);
objWeb.AllowUnsafeUpdates = false;
}
}
});
· The First argument is the Name of your subsite
· Second Argument is the Name of your SubSite.
· Third argument is the Description of you subsite.
· Fouth argument is the LocalId in which you want to create the Site
· Fifth Argument is the Type of Site Template.Since there are many Templates,So here is the code for some of it:
o STS#0 Team Site
o STS#1 Blank Site
o STS#2 Document Workspace
o MPS#0 Basic Meeting Workspace
o MPS#1 Blank Meeting Workspace
o MPS#2 Decision Meeting Workspace
o MPS#3 Social Meeting Workspace
o MPS#4 Multipage Meeting Workspace
o WIKI#0 Wiki
o BLOG#0 Blog
And these are additional web template IDs
o BDR#0 Document center—A central document management location for an enterprise
o OFFILE#0 Records center—A central location in which records
o OFFILE#1 managers can define routes for incoming files
o CMSPUBLISHING#0 Publishing site
o BLANKINTERNET#0 Publishing site—A site for publishing web pages on a schedule with workflow features enabled
o BLANKINTERNET#1 Press releases site
o BLANKINTERNET#2 Publishing site with workflow—A publishing site for web pages using approval workflows
o SPSNHOME#0 A site for publishing news and articles
SPSREPORTCENTER#0 Report center—A site for creating, managing, and delivering web pages, dashboards, and Key Performance Indicators (KPIs)
SPSREPORTCENTER#0 Report center—A site for creating, managing, and delivering web pages, dashboards, and Key Performance Indicators (KPIs)
o SPSPORTAL#0 A starter hierarchy for an intranet divisional portal
o PROFILES#0 A profile site that includes page layouts with zones
o BLANKINTERNETCONTAINER#0 Publishing portal—a site collection preconfigured for revision-controlled, secure content creation and publication
o SPSMYSITEHOST#0 My Site host—keep in mind that only one of these can be provisioned per Shared Services Provider
o SRCHCENTERLITE#0 Search center—A site designed to deliver the search query and results experience
SRCHCENTERLITE#1 Search center—A superset of the previous; does not appear in navigation bars
thanks a lot it work like a charm.
ReplyDeleteRegards,
Mak