I'm using a sandbox solution. I'm trying to add some items to a list from a button click in my webpart.

It seems easy but with sandbox everything becomes difficult.

I'm getting an exception when I do the update(). Here is my code:

if(listToLoad != null)
SPListItem newItem = listToLoad.Items.Add();
            newItem["Title"] = "test";
            //newItem["FieldTitle"] = web.ServerRelativeUrl;
                //newItem["ContentTypeId"] = spCType.Id.ToString();
                //newItem["FieldUrl"] = web.ServerRelativeUrl;
                //newItem["ParentNewsLetter"] = test["FieldTitle"].ToString();
                //newItem["UserGroupName"] = test["UserGroupName"].ToString();
                /*********Exception occurs here*********/

                lbl_message.Text += web.ServerRelativeUrl + "added for parent: " + test["FieldTitle"].ToString() + " and group: " + test["UserGroupName"].ToString() + "<br>";

                foreach (SPWeb _web in web.Webs)
                    LoopThrowSite(_web, test);
            catch (Exception ex)
                throw ex;

Here is the common exception for sandbox.

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

I tried another project as a farm solution and it works, so the issue comes from the sandbox solution. Do you know an alternative to make it work?

  • Do other sandboxed solutions work? It might not be an issue with the code. See if this link helps: sharepointknowledgebase.blogspot.com/2014/03/… – wjervis Jul 16 '14 at 11:19
  • Try by restarting Sandboxed Code Host Service. – Vikram Shityalkar Jul 16 '14 at 11:21
  • yes it works in farm solution but i don't have access to the farm. Do you know an alternative to use a sandbox solution – user1898765 Jul 16 '14 at 11:24
  • i've restarted sevice: Microsoft SharePoint Foundation Sandboxed Code Service without success. Is it possible to do this in sandboxsolution? else do you have an other solution? – user1898765 Jul 16 '14 at 11:31
  • Try a different sandboxeded solution. Farm solutions don't run on SPUCWorkerProcess.exe. – wjervis Jul 16 '14 at 11:35

listToLoad.Update() is not required to add an item. newItem.Update() should be enough.

  • ok but my issue is that newItem thow the exception so my item is never added – user1898765 Jul 16 '14 at 10:18
  • Have you set yourspweb.AllowUnsafeUpdates = true; ? – Sudhakar Jul 16 '14 at 10:20
  • yes i've setted to true before with no more success. – user1898765 Jul 16 '14 at 10:28
  • How did you get handle of listToLoad? It has to be SPList listToLoad= yourweb.Lists["ListName"]; – Sudhakar Jul 16 '14 at 10:50
  • yes i got the list with SPList listToLoad= yourweb.Lists["ListName"]; and i tets if it's not null so it seems to be correct. – user1898765 Jul 16 '14 at 10:52

it's not allowed to add item in sandbox solution so i developped a client script to complete this action

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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