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());
}
}
}
}