I post the question couple days ago and got some help. However, I am still having problem working with document library. I am going to repost my question. I tried to get the file version and move a file to a folder if version is 2 or higher. The first problem I am having is although the Majorversion property of file is 2, the versions count is 1? So I cannot get the latest version.
FileCollection files = list.RootFolder.Files;
ctx.Load(files);
ctx.ExecuteQuery();
foreach (File filein files) //MAJORVERSION = 2
{
FileVersionCollection versions = file.Versions; //COUNT = 1
ctx.Load(versions);
ctx.ExecuteQuery();
if (versions != null)
{
string vl = "";
foreach (FileVersion versionin versions)
{
vl = version.VersionLabel;
//listBox1.Items.Add("File: " + file.Name + " latest version is " + vl);
if (Convert.ToInt32(vl) >= 2)
file.MoveTo(@"\Test Docs\Temp",MoveOperations.Overwrite);
}
}
}
Many thanks.