4

I have a CAML query where I am getting records between a date range for a sharepoint 2010 list through an asmx web method call. It looks like this

<Query><Where><And><Geq><FieldRef Name=\"ows_Created\" /><Value IncludeTimeValue=\"TRUE\" Type=\"DateTime\">2013-01-01T15:55:52Z</Value></Geq><Leq><FieldRef Name=\"ows_Created\" /><Value IncludeTimeValue=\"TRUE\" Type=\"DateTime\">2013-10-22T15:56:29Z</Value></Leq></And></Where></Query>

However, whenever I try adding this as a parameter to the GetListItems webmethod, it's almost as if it completely disregards the query. It returns the first 30 records each time with the date lying outside the range. Here is what my code looks like. Why is it not taking into account my CAML query?

            var client = new inq.Lists();
            client.Credentials = System.Net.CredentialCache.DefaultCredentials;

            XmlElement viewFields = xmlDoc.CreateElement("ViewFields");
            XmlElement queryOptions = xmlDoc.CreateElement("QueryOptions");

            XmlDocument xmldocs = new XmlDocument();
            XmlNode ndQuery = xmldocs.CreateNode(XmlNodeType.Element, "Query", "");
            ndQuery.InnerXml = "<Query><Where><And><Geq><FieldRef Name=\"ows_Created\" /><Value IncludeTimeValue=\"TRUE\" Type=\"DateTime\">2013-01-01T15:55:52Z</Value></Geq><Leq><FieldRef Name=\"ows_Created\" /><Value IncludeTimeValue=\"TRUE\" Type=\"DateTime\">2013-10-22T15:56:29Z</Value></Leq></And></Where></Query>";

            viewFields.InnerXml = "";
            queryOptions.InnerXml = "";

            System.Xml.XmlNode nodeListItems = client.GetListItems(guid, viewid, ndQuery, viewFields, null, queryOptions, null);
4

To solve this issue, just remove the <Query> and </Query> tags from the CAML query it should all work.

  • Not always friend. I built an application where all queries had that tag. Without the tag did not work. – Diego Hillesheim Dec 20 '13 at 10:57
  • What Diego said. When I tried this I got a 'Exception of type Microsoft.Sharepoint.SoapServer.SoapServerException was thrown' – prawn Dec 20 '13 at 15:02
0

I have a CAML Query implemented in C# with the SPListItemCollection.GetItems method, and didn't understand why it was getting all of the items, and not just the one(s) with a specific title. I took out <Query> and </Query> and then it worked as expected.

0

well, just try to adding View Scope='RecursiveAll'. have a look

<View Scope='RecursiveAll'><Query><Where><And><Geq><FieldRef Name=\"ows_Created\" /><Value IncludeTimeValue=\"TRUE\" Type=\"DateTime\">2013-01-01T15:55:52Z</Value></Geq><Leq><FieldRef Name=\"ows_Created\" /><Value IncludeTimeValue=\"TRUE\" Type=\"DateTime\">2013-10-22T15:56:29Z</Value></Leq></And></Where></Query></View>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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