Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

RunWithElevatedPrivileges with Access is denied

$
0
0

Hi,

I've tried to delete a list item with elevated privileges. In SharePoint 2010 (windows authentication) everything works fine. In SharePoint 2013 (claims based authentication) the method throws an "Access is denied" exception in the line "SPList oDelList = oWeb.Lists[ParentListID];"

public static void DeleteListItemElevated(SPListItem oItem)
{
    Guid ParentListID = Guid.Empty;
    Guid ItemID = Guid.Empty;
    String strUrl = "";

    ItemID = oItem.UniqueId;
    ParentListID = oItem.ParentList.ID;
    strUrl = oItem.Web.Url;

    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
        using (SPSite oSiteCollection = new SPSite(strUrl))
        {
            using (SPWeb oWeb = oSiteCollection.OpenWeb())
            {
                try
                {
                    oWeb.AllowUnsafeUpdates = true;

                    SPList oDelList = oWeb.Lists[ParentListID];
                    SPListItem oDelItem = oDelList.GetItemByUniqueId(ItemID);
                    oDelItem.Delete();

                    oWeb.AllowUnsafeUpdates = false;
                }
                catch (Exception ex)
                {
                    // Do something
                    throw;
                }
            }
        }
    });
}

Any suggestion what's going wrong?


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>