SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I understand that you can access comments in an append-only field like:

    public string retrieveComments(SPListItem item)
        SPListItemVersionCollection versions = item.Versions;
        string latestComment = "";

            foreach (SPListItemVersion itemVersion in versions)
                if (itemVersion.IsCurrentVersion)
                    latestComment = itemVersion["Comments"].ToString().Trim();

        catch (Exception e3)
            //handles exception

        return latestComment;

Is there any way to create a new version of the list item and append a comment as the latest comment through C#?

My goal is for someone to email the list and take the body of their email and append it as a comment.

share|improve this question

migrated from Aug 2 '12 at 12:15

This question came from our site for professional and enthusiast programmers.

up vote 7 down vote accepted

You don't need to go through the Versions to get the latest value. That's the current value:


To add a new comment just update the item:

item["Comments"] = "This is now the latest comment";
share|improve this answer
Wow. I honestly thought I tried this already. Thanks so much. Would up-vote but I don't have enough rep! – cbrad Jul 30 '12 at 18:19
Is there a way to add an image attachment as a comment if the user say, sends a screenshot? – cbrad Jul 30 '12 at 18:20
Handled it for you, cbrad. – RJ Cuthbertson Jul 30 '12 at 18:20
Thanks rjcup3, easy answer apparently, but well deserved. Been stuck on this for awhile. – cbrad Jul 30 '12 at 18:23
You can add the image as a standard attachment and then in the comments field have an <img> element pointing to it like: item["Comments"]="Comment with image: <img src='/Lists/TestList/Attachments/2/Test.png' />. Nice";. In this case it's item with ID and the Attachment is named "Test.png" – Per Jakobsen Jul 30 '12 at 18:29

Here is an example:

 List<Message> msgs = new List<Message>
                new Message{Comments=new List<string>{"AS"},IsCurrent=false},
                new Message{Comments=new List<string>{"ASfff"},IsCurrent=true},

            var ress = msgs.Where(ms => ms.IsCurrent); 

            foreach (var ms in ress)
share|improve this answer
I could be wrong but doesn't that just get the latest comment? I want to be able to append a comment as the latest comment. – cbrad Jul 27 '12 at 22:42
Means if the comment is IsCurrentVersion then what you wana do ? – Praveen Jul 27 '12 at 22:43
I want to add a comment, not retrieve them. – cbrad Jul 27 '12 at 22:45
Sorry for late reply, I will give this a try today, thanks. – cbrad Jul 30 '12 at 15:12
How would I go about creating the Message class? – cbrad Jul 30 '12 at 16:09

Posted this on

The answer is simple (which makes me look stupid), and I'm pretty sure I tried it before with no avail, but here it is:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.