How can I pull the Comments History for a field in SharePoint using C#?
I will assume you would like to lookup the list item by ID and that you already have they ID either from a query string or by using LINQ to SharePoint. I will also assume the field name you are looking for is named "Comments History" Int itemId = Convert.ToInt32(Page.Request.QueryString["TaskID"]); //Or however you are getting your ID //Get the SPListItem by Id SPListItem oListItem = lstNECTasks.GetItemByIdAllFields(itemId); if (oListItem.HasPublishedVersion) { //Get the SPListItemVersionCollection SPListItemVersionCollection oVersionInfo = oListItem.Versions; foreach (SPListItemVersion oVersion in oVersionInfo) { //If the Comments History field is found and has a value then do something with it if (oVersion["Comments History"] != null && oVersion["Comments History"].ToString() != "") { //Set a label to the value of the comments history field lblComments.Text += oVersion["Comments History"] ; } } }
This is exactly what I needed. Thank you!