using caml query with owssvr.dll - sharepoint

I am getting an SPList values as xml using the following code.
http://site1/_vti_bin/owssvr.dll?Cmd=Display&List={listGuid}&Query=*&XMLDATA=TRUE
When i pass the following caml query to Query parameter as
http://site1/_vti_bin/owssvr.dll?Cmd=Display&List={listGuid}&XMLDATA=TRUE&Query={<Where><Eq><FieldRef
ID='f382e54b-461d-4f32-8043-3004c428e6eb' /><Value
IncludeTimeValue='TRUE' Type='Text'>1</Value></Eq></Where>}
i am getting empty xml. Can't i use caml query in owssvr.dll service. Or what is wrong with my code

Unfortunately, you cannot use CAML in the service. It does look like you can pull in a view though. The Query parameter takes field names separated by spaces. Check the link here:
http://msdn.microsoft.com/en-us/library/ms416599.aspx
As an alternate, you could call the GetListItems method of the lists.asmx web service. I'm not sure how you're using this data though so that may or may not be an option. The GetListItems web service method will allow you to pass CAML as a parameter to it and returns the same type of formatted results.

Related

SharePoint returns extra system columns

I do query to SherePoint. I have created query, viewquery and query options.
Web services returns me great results, but it include some other system columns such as:
ows_Modified , ows_DocIcon, ows_Editor. I don't want them. How do I return only those which is in ViewQuery string?
My queryoptions is:
#"<QueryOptions>
<IncludeMandatoryColumns>False</IncludeMandatoryColumns><ViewAttributes Scope='Recursive' />
</QueryOptions>";
Thanks!
In order to return only selected columns (and not all of them) use ViewFields property of SPQuery object. You can find some more information about it and a sample code here: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.viewfields.aspx.
In order to do it from javascript, you can try code as written here (that post is on another topic, but it still shows how to specify fields to select): https://sharepoint.stackexchange.com/questions/33683/spservices-today-not-returning-correct-results.

What is the correct SharePoint CAML query to retrieve all items from a list?

For some reason I am trying to query SharePoint 2007 using CAML and web services with the Python suds library. The call looks like:
listItems = client.service.GetListItems(
listName, '', Raw('<Query />'), viewFields, 0,
Raw("""<QueryOptions>
<IncludeMandatoryColumns>TRUE</IncludeMandatoryColumns>
</QueryOptions>"""),
None)
For some reason, I get 0 results or an error with <Query/> or <Query><Where/></Query> but get all items with a simple tautology WHERE x = 1 OR x != 1.
What is the correct way to just get all list items?
To get all items, just put an orderby clause in there, and specify an arbitrary column. Should return everything...
there is a silly thing about it, you have to wrap your Query within a query element. The resulting SOAP envelope looks like
<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>
<soapenv:Body>
<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>
<listName>TestQuery</listName>
<query><Query><Where><Eq><FieldRef Name='Title'/>
<Value Type='Text'>One</Value></Eq></Where></Query>
</query>
<viewFields><ViewFields><FieldRefName='Title'/>
</ViewFields></viewFields><RowLimit>1</RowLimit>
</GetListItems></soapenv:Body></soapenv:Envelope>
As a result, the GetListItems web service decides that your query is wrong and returns no items.
See also this post: GetListItems Webservice ignores my query filter
You are using 0 for rowlimit parameter. Try something like 100.

Sharepoint search all columns of a list

I have a list in sharepoint. I want to search across all the columns for a term. How would you co about doing this?
My idea was to get the SPFieldCollection, get all the fields and generate the CAML on the fly then query the list to get the items. Just wondering if there was a better way to do this as generating the CAML may prove to be difficult.
If you don't like the idea of building the CAML using string concatenation, then you could consider using CAML.Net
I'm accessing SP with webservices, not Object Model. Anyway, I would create the CAML dynamically. Generating the CAML will not be difficult, as you can always tryout your logic with
U2U CAML Query Builder http://www.u2u.net/res/Tools/CamlQueryBuilder.aspx

SharePoint CAML OrderBy Modified does not work

I have made a query against a list. I want to get the last modified item which meets a certain condition, and my query looks like this:
<Query><OrderBy><FieldRef Name='Modified' Ascending='FALSE' /></OrderBy><Where><Eq><FieldRef Name='kortnummer'/><Value Type='String'>kv11</Value></Eq></Where></Query>
I get the listitems i need, just not in the right order. Changing Ascending to true does nothing, so obviously there is something with the OrderBy clause that is not right..
According to MSDN it should be possible to order by Modified.
Any idea why my OrderBy does not work?
I always put the OrderBy after the Where.
Otherwise you could make sure that you are using the internal name. I usually use SharePoint Manager 2007 to get the internal field names. Codeplex SharePoint manager
I can see that on a list in my SharePoint, the modified column internal name is "Last_x0020_Modified".
If you're doing this in a C# string to get an SPListItemCollection, you don't need "<Query></Query>" tags.

CAML Query Help?

Is there a way to get all versions of list item(s) using a CAML Query?
I don't think that's exposed directly in any of the APIs that take CAML queries as parameters. You'll probably need to get the current version of the ListItem using your CAML query and then make another call to get all versions of that item.

Resources