Guest User

Untitled

a guest
Feb 4th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. context.Load(_listitem, tmp => tmp.DisplayName,
  2. tmp => tmp.File, tmp => tmp.File.Versions,
  3. tmp => tmp.FieldValuesAsText);
  4.  
  5. context.ExecuteQuery();
  6.  
  7. if (_listitem.Versions.Count > 0)
  8. {
  9. foreach (ListItemVersion version in _listitem.Versions)
  10. {
  11. if (version.IsCurrentVersion)
  12. continue;
  13.  
  14. int id = version.VersionId;
  15. string lbl = version.VersionLabel;
  16. // I need to get the data for every version of the listitem
  17. }
  18. }
  19.  
  20. static void Main(string[] args)
  21. {
  22.  
  23. string siteCollectionUrl = "https://tenantname.sharepoint.com/sites/sitename";
  24. string userName = "username@tenant.onmicrosoft.com";
  25. string password = "yourpassword";
  26.  
  27. // Namespace: Microsoft.SharePoint.Client
  28. ClientContext ctx = new ClientContext(siteCollectionUrl);
  29.  
  30. // Namespace: System.Security
  31. SecureString secureString = new SecureString();
  32. password.ToList().ForEach(secureString.AppendChar);
  33.  
  34. // Namespace: Microsoft.SharePoint.Client
  35. ctx.Credentials = new SharePointOnlineCredentials(userName, secureString);
  36.  
  37. // Namespace: Microsoft.SharePoint.Client
  38. Site site = ctx.Site;
  39.  
  40. ctx.Load(site);
  41. ctx.ExecuteQuery();
  42. Web web = ctx.Web;
  43.  
  44. ctx.Load(web,w => w.ServerRelativeUrl,w => w.Lists);
  45.  
  46. List list = web.Lists.GetByTitle("List1");
  47.  
  48. ctx.Load(list);
  49. CamlQuery camlQuery = new CamlQuery();
  50. ListItemCollection itemColl = list.GetItems(camlQuery);
  51.  
  52. ctx.Load(itemColl);
  53.  
  54. ctx.ExecuteQuery();
  55.  
  56.  
  57. foreach (ListItem item in itemColl)
  58.  
  59. {
  60. Console.WriteLine(item["Title"].ToString());
  61. ListItemVersionCollection itemversioncollection = item.Versions;
  62.  
  63. ctx.Load(itemversioncollection);
  64.  
  65. ctx.ExecuteQuery();
  66.  
  67. for (int iVersionCount = 0; iVersionCount < itemversioncollection.Count; iVersionCount++)
  68.  
  69. {
  70.  
  71. ListItemVersion version = itemversioncollection[iVersionCount];
  72. Console.WriteLine(version.FieldValues["Title"].ToString());
  73.  
  74. }
  75.  
  76.  
  77.  
  78. }
  79. }
Add Comment
Please, Sign In to add comment