Wednesday, 3 October 2012

Read only fields in some lists? For some users only? Do it yourself as well!

Some months ago I posted a way to hide fields in a list form for some users or in some specific scenarios. A couple of days ago I was reading comments received to previous articles and one of them was asking how to make fields read-only instead of hiding them. It was an old comment so I hope that person has already found a way to do it. For the rest of the audience... here it goes!

How can we do it?
If you check my previous article (click here) you will see that I’m overriding the IsFieldExcluded method to decide whether a field should be shown to the end user. To achieve the desired “Read-Only” behaviour we need to override the CreateChildControls method instead. You can find below how it can be done re-using the same class I created in my previous post. I have added in-line comments to explain what I'm doing...

You need to deploy that dll to the GAC and create your own control template to make these changes visible in your system. I’m not getting into too much detail with those steps because I already described how to do it in Column Security Level in SharePoint? Do it yourself!

Once we have deployed our dll and control template, it is time to test it! As you can see in my in-line comments I have done a basic check of List and Fields by name, but it is obviously just an easy way to show the functionality. This solution should be a lot more robust if you were going to reach a real production environment with it. There are a million ways you could improve it but this is not the goal of this post.

The first image below shows how the form will be presented for an administrator and the second one how it will be presented to a contributor. The Admin Column is only editable by the appropriate user, with admin rights, while contributors can just see the content but they will not be able to modify it in this form. You can make read-only any field type, including custom field types.


  1. i want to make field read only for user wise.

    for ex:- you can only see that particular column
    not edit that column,
    but i can edit that column, how it's possible for
    user wise!!
    seeking for help for this issue,