1

In my DisplayViewWebPart I have a part of my code that need to be protected in the way that the user will only see it on the page if the user is allowed to write/create content on a specific page.

This code runs on my front page:

protected override DataResultSet Result
{
    get
    {
        DataResultSet result = new DataResultSet();
        if (logic to check if user is allowed to write)
        {

        }
        result.Add(new DataResultRow());
        return result;
    }
}

the page the user must have access to is. "http://sites/domain/nyheder/Pages/Forms/AllItems.aspx"

Can someone help me since I'm really stuck at the moment. thanks

Edit

I tried this and it seems to work but I dont know for sure.

using (SPSite site = new SPSite("http://sp16/sites/domain/nyheder/Pages/Forms/AllItems.aspx"))
{
    using (SPWeb web = site.OpenWeb())
    {
        if (web.DoesUserHavePermissions(SPBasePermissions.EnumeratePermissions))
        {
            SPBasePermissions permissionToCheck = SPBasePermissions.ManageLists;

            SPUser user = web.CurrentUser;

            if (web.DoesUserHavePermissions(user.LoginName, permissionToCheck))
            {
                result.Add(new DataResultRow());
            }
        }
    }
}
PaulG
  • 13,871
  • 9
  • 56
  • 78
Carsten Løvbo Andersen
  • 26,637
  • 10
  • 47
  • 77
  • Have you tried the method, SPListItem.DoesUserHavePermissions https://msdn.microsoft.com/en-us/library/ms472022.aspx?f=255&MSPPError=-2147217396 – Piyush Nov 22 '16 at 07:11
  • Do you need to check user permission on the web or ListItem? – Piyush Nov 22 '16 at 09:15

0 Answers0