Tuesday, 23 April 2013

Get the List Items by Version into DataTable

try
            {
                SPListItemVersionCollection objVersionColl = list.GetItemById(ItemID).Versions;
 
                if (objVersionColl.Count > 1)
                {
                    //Navigate to each version of the ListItem
                    foreach (SPListItemVersion objVersion in objVersionColl)
                    {
                        if (iVersionID == objVersion.VersionId)
                        {
                            DataRow dr1 = dt1.NewRow();
                            foreach (SPField field in objVersion.Fields)
                            {
                                if (!dt1.Columns.Contains(field.Title))
                                {
                                    dt1.Columns.Add(field.Title);                                   
                                }
                                dr1[field.Title] = objVersion[field.Title] ==
                             null ? "" : objVersion[field.Title].ToString();
                            }
                            dt1.Rows.Add(dr1);
                            break;
                        }                                         
                    }                   
                }
            }
 

No comments:

Post a Comment