Solved

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

Posted on 2011-03-07
7
2,102 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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…
We had a requirement to extract data from a SharePoint 2010 Customer List into a CSV file and then place the CSV file into a directory on the network so that the file could be consumed by an AS400 system. I will share in Part 1 how to Extract the Da…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now