As a follow up to this post, I have a document that I am downloading from OneDrive library using CSOM.
private static void DownloadFile(ClientContext context, string listTitle, int listItemId, string downloadPath)
{
var list = context.Web.Lists.GetByTitle(listTitle);
var listItem = list.GetItemById(listItemId);
context.Load(listItem, i => i.File);
context.ExecuteQuery();
var fileRef = listItem.File.ServerRelativeUrl;
var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, fileRef);
var fileName = Path.Combine(downloadPath, listItem.File.Name);
using (var fileStream = System.IO.File.Create(fileName))
{
fileInfo.Stream.CopyTo(fileStream);
}
}
Along with the document, I also need to get the document's Major Version, Minor Version, Modified by values etc. However, any code that I have found, only gives me "The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested" when I attempt to get the value from File.ListItemAllFields
property.
How can I access those values?
EDIT: Based on this post The property or field has not been initialized. It has not been requested or the request has not been executed when I try
var listItemCollection = list.GetItems(CamlQuery.CreateAllItemsQuery());
I can see the values in the Add Watch window. The fields in red are the ones I need to access (along with Version).