Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-07
7
Medium Priority
?
2,267 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 15

Accepted Solution

by:
dp_expert earned 2000 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 2000 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 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