Get Minor Version Of File in SharePoint using CSOM

The example in this topic show how to use CSOM to Get Minor Version Of File in SharePoint

  • using Microsoft.SharePoint.Client;
  • using System.Linq;
  •  
  • using (ClientContext clientContext = new ClientContext("http://MyServer/sites/MySiteCollection"))
  • {
  • // clientcontext.Web.Lists.GetById - This option also can be used to get the list using List GUID
  • // This value is NOT List internal name
  • List targetList = clientcontext.Web.Lists.GetByTitle("Documents");
  •  
  • // Option 1: Get Item by ID
  • ListItem oItem = targetList.GetItemById(2);
  •  
  • // Option 2: Get Item using CAML Query
  • CamlQuery oQuery = new CamlQuery();
  •  
  • oQuery.ViewXml = @"<View><Query><Where>
  • <Eq>
  • <FieldRef Name='LinkFilename' />
  • <Value Type='Text'>Document.docx</Value>
  • </Eq>
  • </Where></Query></View>";
  •  
  • ListItemCollection oItems = targetList.GetItems(oQuery);
  • clientcontext.Load(oItems);
  • clientcontext.ExecuteQuery();
  •  
  • oItem = oItems.FirstOrDefault();
  • // Option 2: Ends Here(Above line)
  •  
  • // Get File object of the list item
  • File targetFile = oItem.File;
  •  
  • clientcontext.Load(targetFile);
  • clientcontext.ExecuteQuery();
  •  
  • Console.WriteLine("Minor Version: " + targetFile.MinorVersion);
  • }

Thank you for reading this article. This code was tested in SharePoint 2013


© 2019 Code SharePoint