Project Description
An example of hiding columns from a SharePoint view, based on the identity of the current user.

This behavior is achieved by changing the definition of the current view for the currently rendered page. The code gets a reference to the XsltListViewWebPart and then change the XmlDefinition to remove from the definition the columns that needs to be hidden. This will not affect the view's definition from the schema.xml.
This hiding is only done for the web access and it will not affect SharePoint's interaction with other Office applications (for example, the columns will still be exported in Excel).

The code could be injected in the page by different means: a web part, a server control, page code behind, etc. This example uses custom view page with code behind and does the hiding on the Page_Load event.

To see the result, deploy the project and navigate to the newly created list "TestHiddenColumns - ListInstance1".
"Column3" is visible for admin user:
but hidden for the rest of the users:

Last edited Feb 24, 2013 at 12:58 PM by ctapus, version 7