Hiding a column based on Security permissions.

Was given a problem to solve a few days ago, and was told no custom code could be deployed. The problem was,  is there any way to show/hide a column based on the permissions of a user.  This means that the column needs to be made invisible from display forms for read only users, visible for edit access users, and invisible in views, and that views need to be restricted so users cannot change the view you are giving them.  Here was the full scenario. 

I Have a custom list which has multiple folders in, each folder  has unique permissions, which was done using SharePoint Groups.  The unique permissions was edit permissions on the folder and its items, but the whole list had read rights for every user.   So users could see all items, but only edit items they had access to.

A couple of things need to be done to achieve this, this is what i did.

First of all create a new permission level for the site.  This permission level will have Edit item rights to lists, but will not be able to create views. To do this, open the site in the browser, click on People and Groups from the left navigation, then click on All Permission from the left Navigation and finally select, Settings from the center toolbar and Permission levels

image

Then from the next screen, select "Add a Permission Level", then from the List Permissions section, set the following.  (note: two items will be automatically selected from site permissions section, this is fine).  click Submit.

image

Next,  In SharePoint Designer, open the site and list in question and create copies of AllItems.aspx and DispForm.aspx.  (name them whatever you like, but for the purpose of this blog, i named mine RI_AllItems.aspx and RI_Dispform.aspx.

Now change the List Properties so that the default view is now RI_AllItems.aspx and the ViewForm is RI_DIspform.aspx. (see below)

image

Now open up the RI_Dispform.aspx and right click on the field you wish to hide and select conditional formatting.

image

Now from the right hand navigation, click on "Create" and "Show Content"

image

from the next screen, select Advanced. then and select All from the "select a function category" drop down, then locate and double click on "IfHasRights", this will insert it into the "Edit XPath Expression" box at the top, then in the brackets, insert "4".  click ok, and ok.  Save the RI_DispForm.aspx.

image

Next we need to remove the views drop down (see below) from the default view page.

image

To do this, Open the browser and navigate to the RI_AllItems.aspx (click on the updated left nav link).   Click on Edit Page, then in edit mode, click on the Edit drop down for the list view webpart and select Modify Shared Web Part.

image

Next, from the modify web part settings, and the List Views section, change the Toolbar Type to Summary Toolbar.  This will now remove the drop down for the list views.  (Alternatively you can open the page in SharePoint designer, make this web part invisible and add your own list view webpart and set the toolbar properties there).

image

If when you create your views,  obviously don’t forget that you should only add in the field you are restricting if the users have access to it.  By not providing the default view change down list on a page, you are restricting what a user can select.  The read/edit access will take care of the rest.

6 Responses to “Hiding a column based on Security permissions.”

  1. Kenneth says:

    Hi, I cannot find the field in the SharePoint Designer,
    So I cannot find the conditional Formatting.

  2. Gavin Morgan says:

    Kenneth.

    Apologies but i think i have left a step out of this blog post which requires you to make the existing list form invisible (do not delete), and add a custom list form, that way you get your fields visible on the page.

    I will get the blog post update soon. thanks Gavin

  3. Chris says:

    Kenneth,

    I think this will help you.

    http://www.eggheadcafe.com/software/aspnet/29624812/editing-or-creating-newfo.aspx

  4. Chris says:

    Gavin,

    Is this suppose to hide fields/columns when creating a new form?

    For example: When a basic user creates a new form, I need certain fields to be hidden from users, but should be able to be edited/seen by admins.

  5. Chris says:

    Kenneth,

    Correction: http://blog.henryong.com/2007/09/05/how-to-edit-the-form-fields-of-a-sharepoint-list/

  6. Gavin Morgan says:

    Chris

    The blog was assuming you already created a custom edit form, but thanks for the link, it saves me updating the blog straight away

    Gavin

Leave a Reply