Question

Maybe a simple question, when to use CamlQuery and when to use SPQuery ?

I think that SPQuery is used inside a WebPart running on the SharePoint server, and that CamlQuery is part of the Client Object Model which is used when you connect from a client (CLI, Asp.Net or custom Web Service) to a SharePoint site.

Was it helpful?

Solution

Yes that's right. CamlQuery is a class in the Microsoft.SharePoint.Client.dll which is part of the Client Object Model which can be used through a .NET, Silverlight or JavaScript Application.

While SPQuery is part of the Microsoft.SharePoint.dll which can be used on the Server Side in Farm or Sandbox solutions through Custom C#/.NET code.

OTHER TIPS

You're right SPQuery is part of the Server Side API and CamlQuery is part of the Client Object Model.

So if your code is running on a server in the SharePoint Farm you can use SPQuery.

If your code isn't running on one of the servers, then you can use CamlQuery.

While using CAMLQuery in COB -> make sure you enclose your query with and ofcourse the closure tag - as this is not SPQuery.Query

In CAMLQuery its ViewXML -> not a Query !

my 1 cent !

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top