I need some support as I am struggling to understand what is wrong with my code. I try to retrieve the data of a specific view. The line
camlQuery.ViewXml = view.ViewQuery;
throws an exception
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. Obviously there is something wrong the way I am handling the view, any suggestions?
// ClientContext object is used to get the context for the SharePoint object // Create a client connection ClientContext clientContext = new ClientContext(siteUrl); //user login via Form Authentication clientContext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication; FormsAuthenticationLoginInfo fba = new FormsAuthenticationLoginInfo(siteUser, sitePassword); clientContext.FormsAuthenticationLoginInfo = fba; Web site = clientContext.Web; List list = site.Lists.GetByTitle(ListName); View view = list.Views.GetByTitle(ViewName); ViewFieldCollection viewFields = view.ViewFields; //Create the statement to retrieve the data //pass CamlQuery instance into a method on the List to retrieve the data. //The return value from the GetItems method on the client OM’s List class is a ListItemCollection. //CamlQuery camlQuery = CamlQuery.CreateAllItemsQuery(); CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = view.ViewQuery; //----------------------- ListItemCollection ListColletion = list.GetItems(camlQuery); clientContext.Load(list); clientContext.Load(ListColletion); clientContext.Load(viewFields); clientContext.ExecuteQuery();