SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

After uploading the wsp to the site collection using the browser and activating it, everything seems to work fine and i see all the page layouts, masterpage, content types, lists and webparts. BUT, when I try to add a web part to a web part zone, i get the following error. "Sandboxed code execution request failed" Any suggestions would be helpful. Here is the code in the web part file AnnouncementsWP.cs (its not a visual webpart)

using System;
using System.ComponentModel;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Linq;
using System.Web.UI;

namespace SANDBOXEDSOLUTION.Custom_Web_Parts.AnnouncementsWP
    public class AnnouncementsWP : System.Web.UI.WebControls.WebParts.WebPart
        [WebBrowsable(true), Personalizable(true), WebDisplayName("Announcements List")]
        public string _announcementList { get; set; }

        private String annoucementList = "Announcements";

        protected override void CreateChildControls()
            annoucementList = _announcementList;

        protected override void Render(HtmlTextWriter writer)

                string announcementslist = "";
                SPWeb web = SPContext.Current.Web;

                            if (web.Lists[annoucementList] != null)
                                SPList List = web.Lists[annoucementList];

                                announcementslist += "<div class='carousel g1'><div class='buttons'></div><div class='holder'><ul class='carousel-list'>";
                                foreach (SPListItem li in List.Items)
                                    DateTime date = DateTime.Parse(li.GetFormattedValue("AnnouncementDate"));
                                    announcementslist += "<li><em class='date'><span>";
                                    announcementslist += date.ToString("MMMM") + " " + date.ToString("dd") + ", " + date.ToString("yyyy");
                                    announcementslist += "</span></em><div class='text'><h2>";
                                    announcementslist += li.GetFormattedValue("Title");
                                    announcementslist += "</h2><p>";
                                    announcementslist += li.GetFormattedValue("Announcement");
                                    announcementslist += "</p></div></li>";
                                announcementslist += "</ul></div></div>";
                            announcementslist += "An error has occured in this web part.";

            catch (Exception e)
share|improve this question
did you try it in a local sandbox environment? – Mike Oryszak Nov 24 '11 at 0:08
This might be a dumb question but did you activate the solution in the solution gallery? – Josey Dec 6 '11 at 21:33
Yes, I deployed it to a local sandbox environment and it worked. But this was not sharepoint online, this was sharepoint 2010. – bhavinp Dec 7 '11 at 21:10
Yes, everything is activated. I ended up using out of the box webparts cause I couldn't figure out how to deploy custom ones. – bhavinp Dec 7 '11 at 21:11

I guess that this call will give u an exception if the list doesn't exist: web.Lists[annoucementList]

Instead do web.Lists.TryGetList("NameOfList"); That one will give u a proper null if the list is not there, the first method will actually crash.

Also if GetFormattedValue returns null, for instance to create your DateTime date, this will probably also crash: date.ToString("MMMM")

If none of this works try to write some debug info and use a Controls.Add(new LiteralControl{ Text = "somedebugtext" }); to print out some debug info. Unfortunately the only way to get some decent debug info.

share|improve this answer

Did you check these solutions? -

If these don't work then, there may be something in the code that is being blocked from running by SharePoint.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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