SPQuery : Difference between Query and ViewXml properties?

2.4k views Asked by At

Hello SharePoint developpers !

I can't deeply understand the difference between Query and ViewXml properties in the SPQuery object. In the msdn documentation, it's written :

  • Query : Gets or sets the inner XML used in the query.
  • ViewXml : Gets or sets the XML schema that defines the view.

it seems to me that ViewXml is appropriate to filter the fields you want to retrieve... I'm not sure.

So what's the difference ? in which situations should we choose the first over the second ? How SharePoint is treating those queries .. Mystery remains for me so if someone could throw some light on it ? thank you...

1

There are 1 answers

0
EvgK On BEST ANSWER

ViewXml completly describes query. It can contain Query, ViewFields, RowLimit elements and many more. For SPQuery you should better use corresponding properties (Query, ViewFields, RowLimit etc), and ViewXml will be generated automatically. You can test it by setting this properties for SPQuery object and then look to ViewXml. You should set ViewXml manually if you need to set some specific properties (but as I remember they all can be set using SPQuery properties).