I'm trying to create a web part that will post user comments and save them in a user list, I wrote this code to add a list to the site after adding the web part 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();
But the RunWithElevatedPrivileges method RunWithElevatedPrivileges an exception, I assume that this is a permission problem, the exception is the same as when the site.OpenWeb(); method is site.OpenWeb(); without privilege escalation.
What could be the problem?
sharepoint web-parts
netseng
source share