Showing posts with label SOM. Show all posts
Showing posts with label SOM. Show all posts

Monday, March 7, 2016

How to give a user permissions temporarily and Programmatically

 Run the code with elevated
 code needs to be executed
 private void DeleteTempPDFs(List<SPListItem> convertedItems)
{
    // Elevate the privileges to run code as AppPool administrator
    SPSecurity.RunWithElevatedPrivileges(() =>
    {
     
        using (SPSite site = new SPSite(SPContext.Current.Site.ID))
        using (SPWeb web = site.OpenWeb())
        {
         
            foreach (SPListItem item in convertedItems) {
              web.Lists[item.ParentList.ID].GetItemById(item.ID).Delete();
            }
        }
    });
}