Ergec
Ergec

Reputation: 11824

c# - How to check if current logged in user has access to page in Sharepoint 2013

I'm writing a webpart for Sharepoint 2013. I have the url list of .aspx files under Pages . These are pages like aboutus.aspx, departments.aspx e.t.c. I need to check permissions of these pages for current logged in user and anonymous user. I get the files in a loop and I also have the CurrentUser but have no idea how I compare privileges.

//web.CurrentUser //Current user
foreach(...) {
    SPFile tmpfile = web.GetFile(tmpfilestring); //Page
    //need to compare privileges here
}

Upvotes: 1

Views: 1405

Answers (1)

Madhur Ahuja
Madhur Ahuja

Reputation: 22681

You can use this simple API

SPFile.CanOpenFile method (Boolean, String)

Indicates whether the current user has permission to view the content of the file, specifying a level of access and an output variable to receive an ETag.

http://msdn.microsoft.com/en-us/library/office/ee549635(v=office.15).aspx

Upvotes: 2

Related Questions