I am trying to get some data from a list using the Client Object Model in a console app. It has a number of fields, some are text, some are DateTime, some are Lookups, etc, etc.
It seems to have a problem with field that is called "Folder", all the other fields are fine, but if I try to access the "Folder" field I get the following error message.
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.
The code I used is below.
using (var sourceContext = new ClientContext(SourceUrl)) { var fields = sourceContext.Web.Lists.GetByTitle(SourceLibraryTitle).Fields; sourceContext.Load(fields); sourceContext.ExecuteQuery(); IList<string> viewFields = new List<string>(); foreach (var field in fields) { viewFields.Add(field.InternalName); } var query = CamlQuery.CreateAllItemsQuery(5000, viewFields.ToArray()); ListItemCollection sourceDocuments = sourceContext.Web.Lists.GetByTitle("Documents").GetItems(query); sourceContext.Load(sourceDocuments); sourceContext.ExecuteQuery(); foreach (ListItem sourceDocument in sourceDocuments) { string folderValue = sourceDocument["Folder"].ToString(); // Doesn't seem to like having folder as a field name } }
I have also tried the following
sourceContext.Load(sourceDocuments, items => items.IncludeWithDefaultProperties(i => i["Folder"]));
This works, but again has no effect.
Looking at the CAML query text I can see that the Folder field is included as a ViewField, so this means it is a Field in the Field Collection. This is confirmed during the debugging that this field exists.
During debugging and can see that the "Folder" field is not shown in the FieldValues collection.
Is "Folder" a reserved field name? Unfortunately this is a legacy list and I can't change the name (though the internal name will always be "Folder")
Anyone got any ideas?