Link to home
Start Free TrialLog in
Avatar of dev_ven
dev_ven

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of dp_expert
dp_expert
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dev_ven
dev_ven

ASKER

That makes sense.  Can you help me out by showing a small snippet of how to loop through the various versions?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dev_ven

ASKER

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.
Avatar of dev_ven

ASKER

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.
Avatar of dev_ven

ASKER

The answer was geared more towards the SharePoint model and not the Client Object Model.
Avatar of dev_ven

ASKER

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