This project has moved and is read-only. For the latest updates, please go here.

How to CAML query a view? A.K,A GetViewItems

Nov 22, 2013 at 9:58 PM

I was wondering if it is possible to replicate this with SPServices
SPSite oSiteCollection = SPContext.Current.Site;
using(SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
    SPList oList = oWebsite.Lists["List_Name"];
    SPView oView = oList.Views["View_Name"];

    oView.Query = "<Where><Leq><FieldRef Name=\"Field_Name\" />" +
"<Value Type=\"Number\">1000</Value></Leq></Where>";

Specifically the oView.Query part, namely applying CAML on the result of querying a view.
If it had a name I would call it GetViewItems

Thank you,
Nov 22, 2013 at 11:49 PM
Take a look at Lists.GetListItems. I think it's essentially the same thing.

Nov 23, 2013 at 6:06 PM
Hi Marc,

Thank you for your reply.

Sorry, I should have been more detailed in my post.

I am using GetListItems already, supplying both listName and viewName.
If I also supply a CAMLQuery the View is discarded altogether, and items are queried from the list (all of the items).
As far as I see it, with GetListItems, View and CAMLQuery are mutually exclusive.

What I would like to do is to query with CAML on the items already narrowed down by the View.

Would you know of any way to accomplish this?

Thank you,
Nov 23, 2013 at 10:03 PM
It's an either/or thing. If you request a view and then supply other refinements, they override the view settings. If you supply no refinements, you get the default view.

You could just request the view and then filter further on the client side.