I am trying to read all the versions of a list on a site and store them. I would like to do it for the whole row rather than column by column (or item by item). I have seen this here https://sharepoint.stackexchange.com/questions/137360/how-to-get-all-major-versions-of-list-or-library-item-using-c but cannot get my head around it as none of the oList, items, and listItem does not have "Version" attribute. I have enabled versioning for my list in the SharePoint. Below is my code in C#.
using (ClientContext clientContext = new ClientContext("https://domain.sharepoint.com/sites/mysite"))
{
SecureString passWord = new SecureString();
foreach (char c in "mypass".ToCharArray()) passWord.AppendChar(c);
clientContext.Credentials = new SharePointOnlineCredentials("email@domain", passWord);
Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
CamlQuery query = new CamlQuery();
query.ViewXml = @"";
SP.List oList = clientContext.Web.Lists.GetByTitle("listname");
clientContext.Load(oList);
clientContext.ExecuteQuery();
SP.ListItemCollection items = oList.GetItems(query);
clientContext.Load(items);
clientContext.ExecuteQuery();
foreach (ListItem listItem in items)
{
foreach (KeyValuePair<string, object> dictitem in listItem.FieldValues)
{
//Read this key, value and save them in a datatable
}
}
}
buy using v16 of SharePoint SDK and items.Versions, I get the following error:
Error CS1061 'ListItemCollection' does not contain a definition
for 'Versions' and no accessible extension method 'Versions' accepting a
first argument of type 'ListItemCollection' could be found (are you missing
a using directive or an assembly reference?)