private void CreateSubSites(string parentSiteURL, string siteURLRequested, string siteTitle, string siteTemplateName)
{
const Int32 LOCALE_ID_ENGLISH = 1033;
string newSiteURL = string.Empty;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite siteCollection = new SPSite(parentSiteURL))
{
using (SPSite site = new SPSite(parentSiteURL))
{
using (SPWeb parentWeb = site.OpenWeb())
{
SPWebTemplateCollection Templates = parentWeb.GetAvailableWebTemplates(Convert.ToUInt32(LOCALE_ID_ENGLISH));
SPWebTemplate siteTemplate = Templates[siteTemplateName];
//create subsite
using (SPWeb newSite = parentWeb.Webs.Add(siteURLRequested, siteTitle, "", Convert.ToUInt32(LOCALE_ID_ENGLISH), siteTemplate, false, false))
{
if (!string.IsNullOrEmpty(newSite.Url))
newSiteURL = newSite.Url.ToString();
}
}
}
}
});
}
Example:-
CreateSubSites(SPContext.Current.Site.Url, "Services", "Services", "STS#0");
No comments:
Post a Comment