Provisioning A SharePoint 2010 Site Programmatically Is Very Slow

问题 Provisioning A SharePoint 2010 Site Programmatically Is Very Slow

  • Saturday, April 14, 2012 9:09 PM
     
     

    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?

All Replies

  • Sunday, April 15, 2012 7:48 AM
     
     
    Can you post the code please . That helps to understand your question.

    Sreeharsha Alagani | MCTS Sharepoint 2010 | Linkedin | Blog

  • Sunday, April 15, 2012 9:23 PM
     
      Has Code

    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);
    
                }

  • Monday, April 16, 2012 5:44 AM
     
     

    Thank you. Thats a nice piece of code under the SPLongOperation. Can you post the code under the method - oSiteCreator.createSite(1,2,3);


    Sreeharsha Alagani | MCTS Sharepoint 2010 | Linkedin | Blog

  • Monday, April 16, 2012 9:48 AM
     
      Has Code

    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;
     
                    }
                }



    Sreeharsha Alagani | MCTS Sharepoint 2010 | Linkedin | Blog

  • Monday, April 16, 2012 11:07 AM
     
     

    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?

  • Tuesday, April 17, 2012 9:30 AM
     
      Has Code

    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. 

  • Tuesday, April 17, 2012 9:59 AM
     
      Has Code

    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.


    Sreeharsha Alagani | MCTS Sharepoint 2010 | Linkedin | Blog

  • Tuesday, April 17, 2012 1:43 PM
     
     

    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?