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

Every SPQuery's query should have

<View><Query> query...  </Query></View>

tags?

Sometimes I have to put without those tags to get it work and some times I have to put it with the tags, why is this?

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

If you read these two pages, you'll see that the two different properties require different structure.

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.viewxml.aspx

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.query.aspx

You'll see that ViewXML is the full Query, thus needs the View and Query tags, whereas the Query property is just the "filter" part of the query. SPQuery internally builds up the View and Query elements around the Query property to produce the full CAML Query which appears as the ViewXML property.

share|improve this answer
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.