2

How can i remove items from microfeed list?
When i try to remove items there it says

access denied

I have farm admin priviledges and i am as admin in User Profile Service Application.

Newsfeed gives error

Object reference not set to an instance of an object

and there is one empty entry in that microfeed list which is created there on the same date that the problem started so that is the most probable cause.

I don't know how the empty entry has been created but i'm guessing there is no null check for empty content.

  • Please, check the ULS log for the acces denied error and post the detailed log – Nk SP Aug 12 '15 at 12:09
2

I managed to remove the items from microfeed list that were causing the error with console application by impersonating system account:

static void Main(string[] args)
{
    SPUserToken sysToken = null;
    using (var spSite = new SPSite("http://siteurl"))
    {
        sysToken = GetSystemToken(spSite);

        using (var impersonatedSite = new SPSite("http://siteurl", sysToken))
        {
            using (var web = impersonatedSite.OpenWeb("weburl"))
            {
                var list = web.Lists["Microfeed"];
                var item = list.GetItemById(itemid);
                item.Delete();
            }
        }
    }
}

protected static SPUserToken GetSystemToken(SPSite spSite)
{
    SPUserToken res = null;
    bool oldCatchAccessDeniedException = spSite.CatchAccessDeniedException;
    try
    {
        spSite.CatchAccessDeniedException = false;
        res = spSite.SystemAccount.UserToken;
    }
    catch (UnauthorizedAccessException)
    {
        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            using (var elevatedSPSite = new SPSite(spSite.ID))
            res = elevatedSPSite.SystemAccount.UserToken;
        });
    }
    finally
    {
        spSite.CatchAccessDeniedException = oldCatchAccessDeniedException;
    }
    return res;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.