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
{
[ToolboxItemAttribute(false)]
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)
{
base.Render(writer);
try
{
string announcementslist = "";
SPWeb web = SPContext.Current.Web;
try
{
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>";
}
}
catch
{
announcementslist += "An error has occured in this web part.";
}
writer.Write(announcementslist);
}
catch (Exception e)
{
writer.WriteLine(e.Message);
}
}
}
}