SPSecurity.RunWithElevatedPrivileges(delegate()
{
//SPSite oSIte = SPContext.Current.Site;
SPSite oSIte = new SPSite(SPContext.Current.Site.Url);
SPWeb oWeb = oSIte.OpenWeb();
string url = siteName.Replace(" ", "-");
oWeb.AllowUnsafeUpdates = true;
SPWeb IsWebExists = oWeb.Webs.FirstOrDefault(x => x.Name == siteName);
if (IsWebExists == null)
{
#region Site Creation
//create the site Template of the existing site
webTemplates = oWeb.GetAvailableWebTemplates(1033);
//Get the template with name "Constants.SiteTemplateName" created in the above step
objwebTemplate = webTemplates.Cast<SPWebTemplate>().FirstOrDefault(w => w.Title.ToString() == Constants.SiteTemplateName);
//Get all the site Templates in the site
webTemplates = oWeb.GetAvailableWebTemplates(1033);
//Get the template with name "Constants.SiteTemplateName" created in the above step
objwebTemplate = webTemplates.Cast<SPWebTemplate>().FirstOrDefault(w => w.Title.ToString() == Constants.SiteTemplateName);
//Create the Site Using the template
SPWeb newProjectWorkspace = oWeb.Webs.Add(url, siteName, "Project for"+siteName, 1033, objwebTemplate, false, false);
PublishingWeb area = PublishingWeb.GetPublishingWeb(newProjectWorkspace);
area.MasterUrl.SetValue(newProjectWorkspace.Site.RootWeb.ServerRelativeUrl + "/_catalogs/masterpage/ProjectWorkspaceSystems.master");
area.CustomMasterUrl.SetValue(newProjectWorkspace.Site.RootWeb.ServerRelativeUrl + "/_catalogs/masterpage/ProjectWorkspace.master");
area.MasterUrl.SetInherit(false, true);
area.CustomMasterUrl.SetInherit(false, true);
area.Navigation.GlobalIncludePages = false;
area.Navigation.GlobalIncludeSubSites = false;
area.Navigation.CurrentIncludePages = false;
area.Navigation.CurrentIncludeSubSites = true;
area.Navigation.InheritGlobal = true;
area.AlternateCssUrl.SetInherit(true, true);
_siteUrl = area.Url;
area.Update();
#endregion Site Creation
}
});
{
//SPSite oSIte = SPContext.Current.Site;
SPSite oSIte = new SPSite(SPContext.Current.Site.Url);
SPWeb oWeb = oSIte.OpenWeb();
string url = siteName.Replace(" ", "-");
oWeb.AllowUnsafeUpdates = true;
SPWeb IsWebExists = oWeb.Webs.FirstOrDefault(x => x.Name == siteName);
if (IsWebExists == null)
{
#region Site Creation
//create the site Template of the existing site
webTemplates = oWeb.GetAvailableWebTemplates(1033);
//Get the template with name "Constants.SiteTemplateName" created in the above step
objwebTemplate = webTemplates.Cast<SPWebTemplate>().FirstOrDefault(w => w.Title.ToString() == Constants.SiteTemplateName);
//Get all the site Templates in the site
webTemplates = oWeb.GetAvailableWebTemplates(1033);
//Get the template with name "Constants.SiteTemplateName" created in the above step
objwebTemplate = webTemplates.Cast<SPWebTemplate>().FirstOrDefault(w => w.Title.ToString() == Constants.SiteTemplateName);
//Create the Site Using the template
SPWeb newProjectWorkspace = oWeb.Webs.Add(url, siteName, "Project for"+siteName, 1033, objwebTemplate, false, false);
PublishingWeb area = PublishingWeb.GetPublishingWeb(newProjectWorkspace);
area.MasterUrl.SetValue(newProjectWorkspace.Site.RootWeb.ServerRelativeUrl + "/_catalogs/masterpage/ProjectWorkspaceSystems.master");
area.CustomMasterUrl.SetValue(newProjectWorkspace.Site.RootWeb.ServerRelativeUrl + "/_catalogs/masterpage/ProjectWorkspace.master");
area.MasterUrl.SetInherit(false, true);
area.CustomMasterUrl.SetInherit(false, true);
area.Navigation.GlobalIncludePages = false;
area.Navigation.GlobalIncludeSubSites = false;
area.Navigation.CurrentIncludePages = false;
area.Navigation.CurrentIncludeSubSites = true;
area.Navigation.InheritGlobal = true;
area.AlternateCssUrl.SetInherit(true, true);
_siteUrl = area.Url;
area.Update();
#endregion Site Creation
}
});
No comments:
Post a Comment