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;
try
{
//newItem["ContentTypeId"] = spCType.Id.ToString();
//newItem["FieldUrl"] = web.ServerRelativeUrl;
//newItem["ParentNewsLetter"] = test["FieldTitle"].ToString();
//newItem["UserGroupName"] = test["UserGroupName"].ToString();
/*********Exception occurs here*********/
newItem.Update();
listToLoad.Update();
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?