Saturday, May 24, 2008  by Marc Charmois - About Me / Previous Posts / Archives - Home

Check User Permissions in Windows SharePoint Services or MOSS 2007

Windows SharePoint Services 3.0 implements new types in its object model to support the new security model. Old model is obsolete but keep beeing usable. In Windows SharePoint Services 3.0 or MOSS 2007 sites, you have sometimes to check user, Permissions, Rights, Roles, when loading a page, doing an action, and decide what to do depending on these Permissions. all these Classes are obosolete :
  • SPPermission
  • SPRole
  • SPRights
There is however several Methods working around these tasks, for example :
  • SPSite.CheckPermissions
  • SPSite.DoesUserHavePermissions
  • SPWeb.CheckPermissions
  • SPWeb.DoesUserHavePermissions
  • SPList.CheckPermissions
  • SPList.DoesUserHavePermissions
  • SPListItem.CheckPermissions
  • SPListItem.DoesUserHavePermissions
  • ...
Here is a sample of C# code to check user specific Permission to a web site (SPWeb). For instance, we check if user can edit list items.
Code Sample :

        SPWeb myWeb = SPContext.Current.Site.OpenWeb();


        if (myWeb.DoesUserHavePermissions("DomainName\\user1", SPBasePermissions.EditListItems))


            System.Diagnostics.Debug.WriteLine("user1 can edit lisItems");




            System.Diagnostics.Debug.WriteLine("user1 cannot edit lisItems");


if you are puzzled by "System.Diagnostics.Debug.." and want to know more about DebugView, see...
Use DebugView in Windows SharePoint Services 3.0 programming.


Anonymous itypo said...

Our company developed a small web part for determining effective permissions for the users around SharePoint sites. You can read more about it at or download it free from our company site

Hope it will be helpful for most of you!

May 21, 2010 at 3:47 PM  
Blogger Khushi said...

Can we findout the permission on a web application using code? Every blog mentions the permission check from site collection to item level. I want whether user has permission on a SPWebapplication.

May 10, 2011 at 6:57 PM  
Anonymous Rumah Dijual said...

It has taken me ages to discover your site. Finally. This is just the information I was looking for.

May 9, 2012 at 8:25 AM  
Anonymous Sri Varshan said...

Thanks for the nice article, Have a look at the article "Check User Permissions Programmatically in SharePoint 2010"


November 2, 2012 at 7:02 PM  

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home