Saturday, 31 March 2012

Customizing version.aspx page to show specific metadata

Requirement :

Version.aspx page shows the all metadata changes of all the field of a item. User was required only selected field to be viewed in version.aspx

Approch : We were having two approach
  1. Write our own custom page to show version and iterate all the version of a item
  2. User the existing version.aspx page
Because of the time and effort for development and testing we have select the second approach.

We were customising the sharepoint version.aspx page and decide to hide the not required field of a item.
We made a copy on versions.aspx page and put it into our application folder under layouts.
To hide the not required field put an additional "If" clause check in version.aspx page after the following line:
Search for the following line and Change <% foreach (SPField field in itemcurr.Item.Fields) %> line to <% foreach (SPField field in itemcurr.Item.Fields) { if(field.Title=="fieldTitle"){ %>
}
fieldTitle is name of the field that we wants to hide to be displayed in the version.aspx

we can add additional logic to check the other fields

Now for every version it create a link to view the field, we have disabled the link so that user can only see the version changes. Apply the following css to hide the view link in version.aspx page :
li[text="View"]
{
        display:none;
}