Posts Tagged ‘Permissions’

Check if User Has Permissions on List or WebSite

June 11th, 2010 3 comments

Recently I was working on a web part where I have to check for current user permissions for different lists in multiple sub-sites. I found a very straight forward method from SharePoint API. (DoesUserHavePermissions)

This method has some variations on site and list levels. 

On site level this method can take two parameters, string loginname and SPBasePermissions. You can use these parameters with two variations. If you don’t pass the login name then it verifies the permission level against the current user. SPBasePermissions is an enumeration. You can find more details about SPBasePermissions here.

On list level this method can again take two parameters, but three variations in method parameters. If you just pass the SPBasePermissions then it verifies the permission level against the current user. Then you can check permissions for a specific user and in third variation you can apply folder check. You can find more details on SPList.DoesUserHavePermissions here

You can use this method like this

if (oWeb.DoesUserHavePermissions(SPBasePermissions.ViewPages))
       SPList oList = oWeb.Lists[ListName];

        if (oList.DoesUserHavePermissions(SPBasePermissions.ViewListItems))
         // some smart code