1

I am trying to make a simple query to sharepoint online using Azure function created in VS2017.

My code looks like below:

List mylist = myweb.Lists.GetByTitle(listName);
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View><Query><Where><Neq><FieldRef Name='RequestedForDeletion' /><Value Type='Boolean'>False</Value></Neq></Where></Query><ViewFields><FieldRef Name='LinkTitle' /><FieldRef Name='SiteUrl_x0028_alias_x0029_' /><FieldRef Name='RequestedForDeletion' /><FieldRef Name='CurrentStatus' /></ViewFields><QueryOptions /></View>";
ListItemCollection items = mylist.GetItems(camlQuery);
myclientContext.Load(items);
myclientContext.ExecuteQuery();
log.Info($"Empty items: {items.Count}");

It is the myclientContext.ExecuteQuery(); where I get error as : "The remote server returned an error: (400) Bad Request"

I am unable to understand the reason for this error. Any help or explanation.

1 Answer 1

2

The reason why you are getting this error is because CamlQuery.ViewXml property expects a valid CAML query enclosed within View element.

Here are a few examples on how to construct a CAML query:

For empty query

 var camlQuery = new CamlQuery();
 camlQuery.ViewXml = "<View/>";

For predefined query

var camlQuery = CamlQuery.CreateAllItemsQuery();

For user-defined query:

var camlQuery = new CamlQuery();
                camlQuery.ViewXml = "<View Scope =\"RecursiveAll\"><Query><Where><Eq><FieldRef Name=\"FSObjType\" /><Value Type=\"Integer\">1</Value></Eq></Where></Query></View>";

Rererences

How to: Retrieve List Items

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.