I'm using SharePoint client object model and trying to query specific view but not getting the correct method to do so. Here is my code,

 using SP = Microsoft.SharePoint.Client;

    using (SP.ClientContext _clientcontext = new SP.ClientContext(_context))
        SP.List list = _clientcontext.Web.Lists.GetByTitle("RDSImport");
        SP.View view = list.GetView(new Guid("09F8BD32-8D23-4469-8DC5-D358465196F5"));

      // here is my query which should return all docs from the view

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

        //Now how do apply caml to a view because there is no Getitems() method for view
        //and Client object model seems doesn't support second parameter as "GUID" in  
        //Getitems() method

       //Tried passing following in ViewXml but still not working

       //<View Name="{BDE39CB1-536C-48FB-B3A7-A457833B9196}" DefaultView="TRUE"    
       //Type="HTML" DisplayName="RDSImport">


3 Answers 3


In SharePoint 2013 you can use the SP.View object you mentioned for better detail Check Here

For 2010 It would go along these lines...

query = new Microsoft.SharePoint.Client.CamlQuery();
query.ViewXml = "<View>"
//Include <Query> tag if you wish to query, otherwise skip
+"<Query><Where><Eq><FieldRef Name='Something' /><Value Type='Text'>IsGood</Value></Eq></Where></Query>"

 //Use ViewFields to build the View you wish to return
+"<ViewFields><FieldRef Name='Title' /><FieldRef Name='City' /></ViewFields>"

+ "</View>";

OR I believe you can do

items = list.GetItems();

camlQuery.ViewXml = "<View/>"; isn't going to do anything - you are creating a query that does nothing, and not executing it.

I think what you want to do is retrieve the list of items that would be displayed by the view, aka the items returned by the query that the view uses, which you would do like this:

CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = view.Query;
ListItemCollection collListItem = oList.GetItems(camlQuery);



Here's the MSDN documentation for getting items with the Client Side Object Model from which I've adapted that sample.

  • Thanks. But your code has error in this line, camlQuery.ViewXml = view.Query; view doesn't has property "Query" instead "Viewquery" and if I try that throws an error too.
    – Rishi
    Jun 3, 2013 at 22:52

i tried all solutions provided but this is the correct sequence that worked for me.

Doing this using SP 2010 with Microsoft.SharePoint.Client


add the where conditions, order by items and ViewFields items

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.