List of SharePoint Web Parts

I created a quiz web part in SharePoint 2007, but I'm stuck on one resolution. He must write a quiz score on the list, which he now throws an error when trying. I believe that if the web part has an appropriate permission level, user permissions (polling) do not matter.

Is there a specific permission that should allow webpart to write to the list? In particular:

 SPListItem item = listItems.Add();
+3
source share
1 answer

- , (Contribute). , , . , .

SPSecurity.RunWithElevatedPrivileges(WriteToList);

private void WriteToList()
{
    // create new SPSite and SPWeb objects.  This is important, if you 
    // don't then the write won't use the elevated privileges.
    using(SPSite site = new SPSite(SPContext.Current.Site.ID))
    {
        using(SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
        {
            // Code to Write to the list.
        }
    }
}

. http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx

+2

All Articles