Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2313
  • Last Modified:

How can I display the append-only history comments (v3comments) using the client object model?

Currently, I can only display the current comment using the client object model and was looking to see how I can display all comments for one particular item.

Here's what I have so far.

 Sub Main()   
    Dim clientCtx As New ClientContext("http://sharepointsite")
    Dim clientWeb As Web = clientCtx.Web
    Dim clientList As List = clientWeb.Lists.GetByTitle("Document Letters")
    Dim CAMLQuery As CamlQuery = New CamlQuery
    Dim clientListItems As ListItemCollection = clientList.GetItems(CAMLQuery)
    clientCtx.Load(clientListItems)
    clientCtx.ExecuteQuery()

    For Each clientListItem As ListItem In clientListItems
      Console.WriteLine("      Document: " + clientListItem("FileLeafRef").ToString)
      Console.WriteLine("    Document URL: " + clientListItem("FileRef").ToString)
      Console.WriteLine("Append-Only Comments: " + clientListItem("V3Comments").ToString)
      Console.WriteLine()
    Next
    Console.WriteLine("Finished!")
    Console.ReadKey()
  End Sub

Open in new window


Thanks in advance!
-Mike
0
dev_ven
Asked:
dev_ven
  • 5
  • 2
2 Solutions
 
dp_expertCommented:
You need to iterate the item versions - the "append" functionality is a feature of the web display layer not the data layer. SharePoint is simply displaying the comments from the previous item versions.
0
 
dev_venAuthor Commented:
That makes sense.  Can you help me out by showing a small snippet of how to loop through the various versions?
0
 
dp_expertCommented:
It's C#, I've got it from here http://msdn.microsoft.com/en-us/library/ms415089.aspx
   
 
SPSite oSite = new SPSite("http://yoursiteURL/TestSite");
SPWeb oWeb = oSite.OpenWeb();
SPList oList = oWeb.Lists["MyCustomList"];

SPListItem oListItem = oList.Items.GetItemById(1);

SPListItemVersionCollection oVersionInfo = oListItem.Versions;
                      
int i=0;

foreach (SPListItemVersion oVersion in oVersionInfo)
{
  Console.WriteLine(oListItem.Versions[i]["Comments"].ToString());
  
  i++;
}
Console.ReadLine();

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
dev_venAuthor Commented:
I tested that and it does show the comments for each version.  Any way to get this to work in a Client Object Model?  I notice there isn't a ListItemVersionCollection class.

Again thanks and I'll give you the accepted solution.
0
 
dev_venAuthor Commented:
As I'm finding out more information, I'm beginning to think it's not possible using the Client Object Model.  That's a bit disappointing.

If anyone comes up with additional info; please let me know.

Thanks again.
0
 
dev_venAuthor Commented:
The answer was geared more towards the SharePoint model and not the Client Object Model.
0
 
dev_venAuthor Commented:
Well, I finally found my answer and was able to successfully implement it.

I had to use the lists.asmx service to truly get all of the comments from the append-only field.  I used the GetVersionCollection.

Here's the snippet below:
    Private Sub LayoutRoot_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Dim ListsSVC As New ListsServiceReference.ListsSoapClient

        Try
            ListsSVC.GetVersionCollectionAsync("list id as string", "list item as string", "V3Comments")
            AddHandler ListsSVC.GetVersionCollectionCompleted, AddressOf GetVersionCollection_Success
        Catch ex As Exception

        End Try
    End Sub

    Private Sub GetVersionCollection_Success(ByVal sender As Object, ByVal e As ListsServiceReference.GetVersionCollectionCompletedEventArgs)
        Dim xmlResults As XElement = e.Result
    

        Dim V3CommentsList As List(Of V3Comments) = (From x In xmlResults.Descendants
                                                    Select New V3Comments With { _
                                                                        .V3Comment = x.Attribute("V3Comments").Value, _
                                                                        .V3Modified = x.Attribute("Modified").Value, _
                                                                        .V3Editor = x.Attribute("Editor").Value _
                                                                        }).ToList

        Dim strResults As StringBuilder = New StringBuilder

        For i As Integer = 0 To V3CommentsList.Count - 1
            Dim V3EditorName() As String = V3CommentsList(i).V3Editor.Split("#")
            strResults.AppendLine(V3EditorName(V3EditorName.Length - 1) + " (" + V3CommentsList(i).V3Modified + "): " + V3CommentsList(i).V3Comment)
        Next

        TextBlock1.Text = strResults.ToString
    End Sub

Open in new window

0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now