locked
How to hide labels based on permissions RRS feed

  • Question

  • In my .ascx.cs file i need to hide some labels based on the permission granted to the user loggin in the site. So i need a way to programmatically get the user type (member, owner, visitor, viewer) and then check the permission level. Or is there another way to do this?
    Monday, October 18, 2010 3:07 PM

Answers

All replies

  • I think programatically manipulation is best way. Go through this post to get Groups, Users and etc.

    How to get all groups, users and roles from SharePoint using SPGroup, SPUser, SPRole objects.


    Regards, Sandip Patil, .Net,Sharepoint Developer www.worldofsharepoint.com
    Monday, October 18, 2010 4:00 PM
  • Hi MMaik,

    Try to use the SPWeb.DoesUserHavePermissions method

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurableobject.doesuserhavepermissions.aspx

    Kind Regards,

    Joran Markx


    Joran Markx DiVa BV (The Netherlands) Blog - http://blog.diva.nl Website - http://www.diva.nl
    • Proposed as answer by Doug WareMVP Monday, October 18, 2010 8:40 PM
    • Marked as answer by MMaik Tuesday, October 19, 2010 7:00 AM
    Monday, October 18, 2010 7:27 PM
  • Hi Joran,

    I am triyng to use the SPWeb.DoesUserHavePermissions method, but i don't understand how it works. I see i have to pass a SPBasePermissions parameter, but i cannot figure out what it actually is (cannot even clearly understand what "A bitwise combination of enumeration values" means)

    I am very confused, can you provide a code example please? 

    Thanks

    EDIT: i got it on my own:

    if

     

     

    (SPWeb.DoesUserHavePermissions(SPBasePermissions.ViewListItems)) { ... }

    Tuesday, October 19, 2010 6:26 AM
  • Good work!

    A bitwise combination of enumeration values means you can combine multiple enumeration values using the | or & operator.

    if (SPWeb.DoesUserHavePermission(SPBasePermission.ViewListItems | SPBasePermissions.EditListItems) // View or Edit permissions
    {
     // do things
    }
    
    if (SPWeb.DoesUserHavePermission(SPBasePermission.ViewListItems & SPBasePermissions.EditListItems) // View and Edit permissions
    {
     // do things
    }
    
    
    

    Kind regards,
    Joran Markx


    Joran Markx DiVa BV (The Netherlands) Blog - http://blog.diva.nl Website - http://www.diva.nl
    Friday, October 22, 2010 7:50 AM