Provisioning A SharePoint 2010 Site Programmatically Is Very Slow
-
2012년 4월 14일 토요일 오후 9:09
I am provisioning a subsite using the SPSiteCollection.Add() method in an SPLongRunningOperation. It works and the site is created correctly but very very slowly. I am showing a processing page while the long operation runs.
Why does it take so long to provision a site programmatically?
모든 응답
-
2012년 4월 15일 일요일 오전 7:48
-
2012년 4월 15일 일요일 오후 9:23
Here is the code in the Page_Load of an aspx application page that I have added to my feature:
try { SiteCreator oSiteCreator = new SiteCreator(); string siteUrl = oSiteCreator.CheckSiteExists(Context.Request["SiteUrl"], Context.Request["List"], Context.Request["ItemId"]); string TempURL = oSiteCreator.getURL(Context.Request["SiteUrl"], Context.Request["List"], Context.Request["ItemId"]); if (siteUrl != "") { SPUtility.TransferToSuccessPage("A site already exists for this place. Click OK to navigate to the site.", siteUrl, "Click here", ""); } using (SPLongOperation loperation = new SPLongOperation(this.Page)) { //….. your code here …. loperation.LeadingHTML = "Provisioning the Site. This May Take A While."; loperation.TrailingHTML = "Please Wait ..."; loperation.Begin(); string SiteUrl = oSiteCreator.createSite(Context.Request["SiteUrl"], Context.Request["List"], Context.Request["ItemId"]); loperation.End(SiteUrl, Microsoft.SharePoint.Utilities.SPRedirectFlags.DoNotEncodeUrl, HttpContext.Current, null); } } catch (ThreadAbortException tAex) { /* Thrown when redirected */ } catch (Exception ex) { SPUtility.TransferToErrorPage(ex.Message); }
-
2012년 4월 16일 월요일 오전 5:44
-
2012년 4월 16일 월요일 오전 9:48
This is the code am using and it hardly takes 10 seconds to create site . Am using a team site template. What template are you using to create your subsite.web.AllowUnsafeUpdates = true; using (SPSite site = new SPSite("Site Url")) { using (SPWeb web = site.OpenWeb()) { web.AllowUnsafeUpdates = true; SPWebCollection objWebs = web.Webs; objWebs.Add("SubSite1", "SubSite1", "This is the sub Site", 1033, "STS#0", true, false); web.AllowUnsafeUpdates = false; } }
-
2012년 4월 16일 월요일 오전 11:07
I have a similiar issue currently and it is related to the 'Content Type Syndication Hub'. If you are pushing a lot of content types to a site collection on the same web application where you are creating the new site collection.
Are you using the Syndication Hub?
-
2012년 4월 17일 화요일 오전 9:30
Sreeharsha,
I am using very similar code:
if (!CheckSiteExists(aSite.Url, webPath)) { theWeb = aSite.OpenWeb(); theWeb.AllowUnsafeUpdates = true; SPWebCollection subSites = theWeb.Webs; string siteDescription = ""; string aSiteTemplate = C.GetValue(TheADetail.aType + " Site Template"); // Get the name of the site template to use SPWebTemplateCollection webTemplates = aSite.RootWeb.GetAvailableWebTemplates(1033); SPWebTemplate webTemplate = (from SPWebTemplate t in webTemplates where t.Title == aSiteTemplate.ToString() select t).FirstOrDefault(); subSites.Add(TheADetail.aID, TheADetail.aTitle, TheADetail.aTitle, 1033, webTemplate, true, false); theWeb.AllowUnsafeUpdates = false; } else { return aSiteUrl + "/" + TheADetail.aID; } return aSiteUrl + "/" + TheADetail.aID;But in my case I am using a Custom .wsp site template. So I am getting back the template into a SPWebTemplate object and using it in the SPSiteCollection.Add(...) function.
It is taking upwards of 4 minutes to create the site which is not acceptable.
Luke Kennedy - I have a lot of content types in my site collection but I am not creating a site collection. I am creating a web in this case.
-
2012년 4월 17일 화요일 오전 9:59
I believe from the above snippet, it might be slow becoz of the template that you might be using. The size of it , the number of read writes to the Database.
Just replace your template with
STS#0
and check if that makes a difference. If it does, then you need to look at your site template. Make sure all the content you have is relevant and required to be used as a template.
-
2012년 4월 17일 화요일 오후 1:43
Creating a site manually using the site template is not slow.
I would expect programmatically creating a site using the same site template would be faster if anything?

