I'm trying to make a web part that greps user comments and stores it in custom list, I wrote this code to add a list to the site once the web part added to the page,
[Guid("c314a0e8-0210-4064-b79e-bfd3594c6083")]
public class CommentWriteSpace : System.Web.UI.WebControls.WebParts.WebPart
{
SPSite site = null;
SPWeb web = null;
public CommentWriteSpace()
{
SPSecurity.CodeToRunElevated foo = new SPSecurity.CodeToRunElevated(doit);
SPSecurity.RunWithElevatedPrivileges(foo);
SPListCollection listCollection = web.Lists;
Guid listGuid = listCollection.Add("Comments List", "A list of user comments", SPListTemplateType.GenericList);
listCollection[listGuid].Fields.Add("User", SPFieldType.User, true);
listCollection[listGuid].Fields.Add("Comment", SPFieldType.Text, true);
listCollection[listGuid].OnQuickLaunch = true;
listCollection[listGuid].Update();
//this.Page.Request.Url.ToString()
}
public void doit()
{
site = SPContext.Current.Site;
web = site.OpenWeb();
}
}
But the RunWithElevatedPrivileges
method throw an exception, I guess it's a permission issue, the exception is the same as one appears when executing site.OpenWeb();
method without elevating privileges.
What could be the problem?