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:
Using Server Object Model
SPListItemVersionCollection objVerisionColl = objItem.Versions;
foreach (SPListItemVersion objVersion in objVerisionColl)
{
if (objVersion.IsCurrentVersion)
{
latestComment = objVersion["Comments"].ToString().Trim();
}
}
- 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.
Using Server Object Model
SPListItemVersionCollection objVerisionColl = objItem.Versions;
foreach (SPListItemVersion objVersion in objVerisionColl)
{
if (objVersion.IsCurrentVersion)
{
latestComment = objVersion["Comments"].ToString().Trim();
}
}
What if we just want to return the latest version? Not all of the versions?
ReplyDeleteif (objVersion.IsCurrentVersion)
DeleteAlways gives you latest version not all of the versions.
For getting each version, you need to remove
if (objVersion.IsCurrentVersion)
Hi
ReplyDeleteSee 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