Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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">
       //</View>

      }
share|improve this question
add comment

2 Answers 2

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();
context.load(items,"Include(Title,Author)");
context.executeQueryAsync(.....)
share|improve this answer
add comment

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);

clientContext.Load(collListItem);

clientContext.ExecuteQuery();

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

share|improve this answer
    
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 '13 at 22:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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