Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Problem Adding ListItem with RunWithElevatedPrivileges

  Asked By: Tarak    Date: Feb 06    Category: Sharepoint    Views: 1816

What I'm attempting to do is Submit form information to a ListItem
with eleveated privileges, so users with general read only access can
submit items to the list without being able to view any of the list
items.. code works fine unless I'm logged in as one of those users
with readonly access - it does to the 'Access Denied' screen.

Heres the code:

void OKButton_Click(object sender, EventArgs e)
{

SPWeb web = SPContext.Current.Web;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
///Site Collection object running under the
///security context of the Application Pool Identity
using (SPSite siteCollection = new SPSite(web.Site.ID))
{
//Perform actions that may require elevated privileges
SPList srcList = web.Lists["TESTLIST"];
web.AllowUnsafeUpdates = true;
SPListItem listitem = srcList.Items.Add();
listitem["Title"] = subject.Value;
listitem.Update();
//listitem.SystemUpdate();
}
});


}


It's probably something simple - I try and understand how to use
RunWithElevatedPrivileges but still can't quite grasp..

Any ideas?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Vidisha Pathak     Answered On: Feb 06

You can also try impersonation

 
Didn't find what you were looking for? Find more on Problem Adding ListItem with RunWithElevatedPrivileges Or get search suggestion and latest updates.