Solved

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

Posted on 2011-03-07
7
2,143 Views
Last Modified: 2012-05-11
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
Comment
Question by:dev_ven
  • 5
  • 2
7 Comments
 
LVL 15

Accepted Solution

by:
dp_expert earned 500 total points
ID: 35067122
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
 

Author Comment

by:dev_ven
ID: 35069565
That makes sense.  Can you help me out by showing a small snippet of how to loop through the various versions?
0
 
LVL 15

Assisted Solution

by:dp_expert
dp_expert earned 500 total points
ID: 35069711
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:dev_ven
ID: 35070789
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
 

Author Comment

by:dev_ven
ID: 35072268
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
 

Author Closing Comment

by:dev_ven
ID: 35072283
The answer was geared more towards the SharePoint model and not the Client Object Model.
0
 

Author Comment

by:dev_ven
ID: 35167572
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary In SharePoint 2010 it is easy to create custom color themes to jazz up a site. Theme colors can also be created in PowerPoint 2010 with a few clicks. But how do the chosen colors actually look in the SharePoint site? The attached PowerPoint…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question