Hi @Deepthi Vangapandu
We can use FileVersion.IsCurrentVersion
property to check and get current version. Please refer to the following code
using (ClientContext clientContext = new ClientContext("http://xxx.sharepoint.com/sites/MySiteCollection"))
{
List targetList = clientcontext.Web.Lists.GetByTitle("Documents");
ListItem oItem = targetList.GetItemById(13);
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();
FileVersionCollection oFileVersionCollection = oItem.File.Versions;
clientcontext.Load(oFileVersionCollection);
clientcontext.ExecuteQuery();
foreach (FileVersion oFileVersion in oFileVersionCollection)
{
if (oFileVersion.IsCurrentVersion)
{
Console.WriteLine("Current Verrsion of the file: " + oFileVersion.VersionLabel);
}
}
}
Here is the details about FileVersion.IsCurrentVersion
property
https://learn.microsoft.com/en-us/previous-versions/office/sharepoint-csom/ee539266(v=office.15)
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.