Wednesday 9 January 2013

view SharePoint 2010 list field version history

In SharePoint 2010 if we want to see the history of multiline text field whose version is enabled (Appending item); We need to follow the below step:

  • Create a multiple lines of text type of field with “Append Changes to Existing Text” option enabled.
  • Go to edit xslt view in SharePoint Designer.
  • By default, when we enabled “Append Changes to Existing Text”, it will display “View Entries…” for the multiple lines field. We will remove the “View Entries…” and replace it with version details of current field.
  • In Design mode, select Xslt list view web part > click Design on the ribbon > Customize XSLT > Customize Entire View.
  • Still in Design mode, select “View Entries…” and type “testtest” directly to replace it with “change”.
  • Switch to code mode, find “change”, and replace it with following code.
  • <SharePoint:AppendOnlyHistory runat="server" FieldName="<Field Display Name>" ItemId="{$thisNode/@ID}" ControlMode="Display" />
  • Done and save the changes.
$thisNode/@ID is very important part here

Using Server Object Model

 SPListItemVersionCollection  objVerisionColl = objItem.Versions;
foreach (SPListItemVersion objVersion in objVerisionColl)
            {
                if (objVersion.IsCurrentVersion)
                {
                    latestComment = objVersion["Comments"].ToString().Trim();
                }

            }

3 comments :

  1. What if we just want to return the latest version? Not all of the versions?

    ReplyDelete
    Replies
    1. if (objVersion.IsCurrentVersion)
      Always gives you latest version not all of the versions.

      For getting each version, you need to remove
      if (objVersion.IsCurrentVersion)

      Delete
  2. Hi

    See http://www.manageprojectsonsharepoint.com/blog/2014/07/25/show-content-sharepoint-2013-append-rtf-column-view/ for some easy to follow steps on how to enable this in SharePoint 2013

    Question - is the Object Model method the only way to limit it to showing only the latest comment?

    Thanks

    ReplyDelete