0

The below query returns the entirety of the List, instead of those which fall inside the correct date range.

I have tried querying with and without a time added to the date.

            CamlQuery CamlQuery = new CamlQuery();
            var qs = "<Query>" +
                    "  <Where>" +
                    "    <And>" +
                    "      <Geq>" +
                    "        <FieldRef Name='Created' />" +
                    "          <Value IncludeTimeValue='True' Type='DateTime'>2017-08-30T00:00:00Z</Value>" +
                    "      </Geq>" +
                    "      <Leq>" +
                    "        <FieldRef Name='Created' />" +
                    "        <Value IncludeTimeValue='True' Type='DateTime'>2017-08-31T23:59:00Z</Value>" +
                    "      </Leq>" +
                    "    </And>" +
                    "  </Where>" +
                    "</Query>";

            CamlQuery.ViewXml = qs;

1 Answer 1

1

You are missing the View tag around your whole CAML string:

            CamlQuery CamlQuery = new CamlQuery();
            var qs = "<View><Query>" +
                    "  <Where>" +
                    "    <And>" +
                    "      <Geq>" +
                    "        <FieldRef Name='Created' />" +
                    "          <Value IncludeTimeValue='True' Type='DateTime'>2017-08-30T00:00:00Z</Value>" +
                    "      </Geq>" +
                    "      <Leq>" +
                    "        <FieldRef Name='Created' />" +
                    "        <Value IncludeTimeValue='True' Type='DateTime'>2017-08-31T23:59:00Z</Value>" +
                    "      </Leq>" +
                    "    </And>" +
                    "  </Where>" +
                    "</Query></View>";

            CamlQuery.ViewXml = qs;
3
  • Wow. that was it! Aug 31, 2017 at 20:22
  • On a somewhat related note, is it possible to use Linq instead of CAML? I`ve looked but what ive seen asks for SPMetal on the server which i wont have access to. Aug 31, 2017 at 20:23
  • Linq to SharePoint requires SPMetal. SPMetal can be found on any SharePoint installation, in the hive\bin folder. However, this also requires the code using Linq to SharePoint to run on the server itself, with the server-side object model. It cannot be used with the CSOM.
    – Evariste
    Aug 31, 2017 at 20:29

Your Answer

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

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