0

I have a event receiver in my project and in the event receiver I have following code. It is bound to custom list.

public override void ItemAdding(SPItemEventProperties properties)
   {
       base.ItemAdding(properties);

// Get the web where the event was raised

       SPWeb spCurrentSite = properties.OpenWeb();

       //Get the name of the list where the event was raised         

       String curListName = properties.ListTitle;

       //If the list is our list named SubSites the create a new subsite directly below the current site

       if (curListName == "Customers")
       {

           //Get the SPListItem object that raised the event

           SPListItem curItem = properties.ListItem;

           //Get the Title field from this item. This will be the name of our new subsite
           String curItemSiteName = properties.AfterProperties["Title"].ToString();

           //Get the Description field from this item. This will be the description for our new subsite

           string curItemDescription = properties.AfterProperties["Description"].ToString();

           //Update the SiteUrl field of the item, this is the URL of our new subsite

           properties.AfterProperties["SiteUrl"] = spCurrentSite.Url + "/" + curItemSiteName;

           //Create the subsite based on the template from the Solution Gallery

           SPWeb newSite = spCurrentSite.Webs.Add(curItemSiteName, curItemSiteName, curItemDescription, Convert.ToUInt16(1033), "WIKI#0", false, false);

           //Set the new subsite to inherit it's top navigation from the parent site, Usefalse if you do not want this.
           newSite.Navigation.UseShared = true;
           CreateList(newSite);
           newSite.Close();

       }

   }

This code works fine for farm solutions. For sandbox solutions it gives exception at :

SPWeb newSite = spCurrentSite.Webs.Add(curItemSiteName, curItemSiteName, curItemDescription, Convert.ToUInt16(1033), "WIKI#0", false, false);

Says

The sandboxed code execution request was refused because the Sandboxed Code Host Service was too busy to handle the request.

Any suggestion?

1
  • Sandboxed code has resource restraints, if you google your error you will see that it's caused by this limitation. On-premise this limit can be changed but I don't know about SharePoint Online. Commented Mar 31, 2014 at 5:58

1 Answer 1

2

Sandbox code has resource usage limitations. There is a hard limit to how long a sandboxed solution can take to be completed. By default, this is 30 seconds. if it takes more than 30 secs then it will be terminated.May be your code is taking more than 30 secs since i can see Create sub site code is there which normally takes time.

Please see this Resource usage limits on Sandboxed solution

To verify this, i would suggest try removing the spCurrentSite.Webs.Add line of code and see whether your code works.

There are ways to increase this default execution Time Out value, but that requires farm level permissions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.