1

I am using the below code for retrieving all sharepoint lists from a site.

SPSite site = new SPSite("http://servername:port");
SPWeb web = site.OpenWeb();
SPListCollection SPlists = web.Lists;
foreach (SPList list in SPlists)
  {
    // do something
  }

But while deploying it shows the error

"Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred."

Any ideas how can we get sharepoint lists and list items from a a site in sandboxed solution?

2

Not 100% suer, but I think that SPSite constructor is not allowed in sandboxed mode, so You have to obtain your SPSite instance differently.

0

The error you are getting is a very generic sandbox error. This error can be thrown due to a variety of reasons by the SharePoint Sandbox.

Can you debug with Visual Studio? I would suggest you use some kind of logging mechanism if you cannot debug your solution directly with VS. Try the following code:

try
{
    using(SPSite site = new SPSite("http://servername:port"))
    {
        using(SPWeb web = site.OpenWeb())
        {
            SPListCollection SPlists = web.Lists;
            foreach (SPList list in SPlists)
            {
                // do something
            }
        }
    }

}
catch(Exception ex)
{
    Page.Controls.Add(new LiteralControl("<div>"+ ex.Message() +"</div>"));
}
  • while debugging it does not throw any error! I will get the lists successfully, But the error is shown when in the sharepoint page – sharmila Oct 29 '12 at 6:56
  • Then I guess this has something to do with the Environment. Make sure all the sandbox processes and services are running properly. – Vardhaman Deshpande Oct 29 '12 at 7:26
  • They are running....one thing i found that if i use SPContext.Current.Web.Lists then the code will not throw exception. But i need to find a way other than this. any ideas? – sharmila Oct 29 '12 at 7:55
0

Can you find what exactly happens using SharePoint Log Viewer?

http://sharepointlogviewer.codeplex.com/

0

You can only access the CURRENT context inside sandboxed code, ergo a correction to this code would be

SPListCollection SPlists = SPContext.Current.Web.Lists;
foreach (SPList list in SPlists)
  {
    // do something
  }

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.