DISQUS

SharePoint Magazine: Writing CAML Queries For Retrieving List Items from a SharePoint List

  • Arno Nel (SharePoint Magazine) · 1 year ago
    wow, great introduction to CAML from the CAML girl herself :)
  • Bjørn Furuknap · 1 year ago
    Great article!

    I would like to point out a great tool by John Holliday called CAML.net which helps write the CAML code for you and prevents quite a lot of typo errors. It is available on CodePlex at http://codeplex.com/camldotnet/

    .b
  • Garth · 1 year ago
    Karin,
    Thank you for this posting. I've been doing a fair amount of CAML lately and have used this page as a starting point for alot of my work.

    Thanks
  • Karine Bosch · 1 year ago
    There exist a number of community tools that help you generate your CAML. Another tool is the U2U CAML Query Builder. Besides a user interface in which you can design your queries, you can also use the DLLs from within your code to generate the necessary CAML.
    Karine
  • vin · 1 year ago
    Hi Karin,

    After successfully retrieving the records using the GetListItems method, how can I use the result so I can insert it in a SQL table?

    Thanks in advance
  • Heiko Hatzfeld · 1 year ago
    Thanks for a great post.

    Very interesting and informative overview.
  • Santro · 1 year ago
    Hello Karine,
    Thanks a lot for the wonderful post. I read the full post and just got every thing which I was looking for.
  • masha · 11 months ago
    thank you for great article=)
  • jamil · 11 months ago
    this is the best, simple, attractive, satisfying, shortest article i have read in my life. you have an amazing way!!!!
  • martin · 11 months ago
    ...also, be sure that authentication as enabled at endpoint... (lost a good hour there)
  • john · 11 months ago
    Thank you, thank you. I wish I had saw this post last week. This cleared up a lot of questions!
  • Akshaya · 11 months ago
    Hi

    I use the U2U caml builder gor queries and I use the shpt web services to retrieve data.

    I am facing a problem. When I want to get the data from a particular view of the list, I pass the view name of the getlistitems method and it returns me the rows belonging to that view only.

    However, when I try getting the data from a view based on a query, the query returns the data from the all items view rather than from that particular view only, and as a result I get extra rows, what should i do to prevent this?

    Thanks a lot

    Akshaya
  • agnel · 11 months ago
    My list contains folders as list items.Can anyone help how to sort folder in list.
  • sayvidyasagar · 10 months ago
    Excellent introduction on CAML query creation. In real time I am facing some prolem, can any one please suggest me the solution. In SharePoint list I have 5 columns: Title, Description, submitter, status and Published Date. My query should be like:
    (Status = ‘Published’ AND Published Date=’10/10/2008’) AND (title contains ‘xyz’ OR descrition contains ’abcd’ OR submitter conains ‘aaa’)
  • John Dieter · 9 months ago
    How can you debug SPException "Cannot Complete this action" ? My query looks fine. But if I try to access myListItemCollection.Count I get the error
  • Andrew · 9 months ago
    Hello. Thank you for the helpful article.

    I'm curious - has the method for expanding recurring calendar events over webservices been tested?

    I have been able to get it working "server-side", as described in the iCal article; however - no combination of options seems to work for expanding recurring events using the web services interface.
  • Florian · 8 months ago
    Hello, I m lookin to retrieve the direct link to a document in my CAML query result, who can I do that??
    I'm usintgSPSIteDataQuery accross multiple SubSite and use the SPWeb.GetSiteData(myCamlQuery)
    thanks in advance!
  • Dylan · 6 months ago
    Hi Boske,

    This is the only place that I found this useful information about getting Calendar data throug lists.asmx webservice. But I got a problem and not sure why it behave this way. Basically, I was able to get calendar data from this month with all recurrence events. But when I click Next month, I put this code like you suggest in QueryOptions to set CalendarDate to the next month but it doesn't seem to effect anything. It's always return me the all events for the current month and upto the same day next month (e.i: if I query from today 4/21/2009, I'll get everything from April upto May 21) I can't seem to get further. Please help...

    Thanks



    XmlNode queryOptionsNode = camlDocument.CreateElement("QueryOptions");queryOptionsNode.InnerXml = "<ExpandRecurrences>TRUE</ExpandRecurrences>" + "<CalendarDate>2009-05-21T01:00:00Z</CalendarDate>";
  • Tim Landgrave · 5 months ago
    Is there any (easy) way to call Lists.ASMX from an Infopath 2007 form and use the results in a dropdown?
  • Jennifer Lewis · 5 months ago
    Excellent post, Karine!

    This is one of the best posts that I've read on CAML. It's straightforward yet thorough. Unlike other articles that I've read about CAML, this one covers all scenarios.

    Thank you very much!
  • Zarko · 5 months ago
    I am building a custom workflow in SharePoint and I ise CAML query to retrive data about status of the task. However, at one point, an error started to arise: One or more field types are not properly installed... I checked internal nemes and everything is fine. The strangest thing is that the same code worked before. What can be the cause? I would extremely appriciate your help.

    Thanks in advance
  • asdasd · 4 months ago
    Not able to get Recurrence Data in the response even after adding <ExpandRecurrences>TRUE</ExpandRecurrences>
    Any suggestions
  • vinod · 4 months ago
    Hi Karine n others,

    Is it possible to write a CAML query within a CAML query.Please help me out.Thank you.
  • bamarob55 · 3 months ago
    I'm having trouble getting all the fields to return. I'm having trouble with any fields that have a space in the field name. I.e.:

    ndViewFields.InnerXml = "<FieldRef Name='Last Name'/><FieldRef Name='Author'/><FieldRef Name='Department'/><FieldRef Name='Crew'/>"

    works fine to return Author, Department, and Crew, but the Last Name field doesn't get returned. Any tips you can provide would be much appreciated.

    I'm using the "Retrieving List Items with CAML using the SharePoint Web Services" method.

    Thanks,

    Robert
  • scvinod · 3 months ago
    @bamarob55

    that must becoz the internal field name of of the column "last Name"would different from what you see.Please get the internal field name by this code "list.Fields["Manager"].InternalName.ToString();" and then put the name tht u get in the CAML query.
  • scvinod · 3 months ago
    Hi Karine and others,

    Hey guys i have column called "Managers" in my list in which i have to more than 1 value like this "vinod:sc" which means vinod and sc are the 2 managers.Is it possible in my CAML query to get the 2 values separately ???
  • scvinod · 3 months ago
    Hi all,

    Is it possible to write an IF function in a CAML query or is it possible to use a valure returned from a function???
  • sharepoint guy · 3 months ago
    you need to use <Today OffsetDays="1" /> instead of <Today Offset="1"/> to make query work.
  • scvinod · 3 months ago
    Hi Ms.Karine,

    I'm not able to retrieve a column from a sharepoint list that has some empty values.I'm getting this error "Object referrence not set to instance of an object".Can anyone please help me out.
  • suzanne · 3 months ago
    I installed the Employee training site template and have lists associated with that template. One of the lists is Past Registrations where items from another list are moved by workflow after an event. Weird thing: a query of this list (with no conditions) does not return all list items. What can I do?
  • suzanne · 3 months ago
    I solved my problem by using U2U CAML builder. Great app!!!
  • sandeepnahta · 3 months ago
    Offset option didn't work . it has to be OffsetDay='-7'
  • sweha · 3 months ago
    Hi,

    I am trying to get listitems using the same method. I have a order no field in the list and some other fields are Customers which is a lookup and date which is a calculated column and Agency which is a text.

    I am querying by order no.

    I can retrieve Agency as it is a simple text, but I can't seem to get Customer name and Date as one is a lookup and one is a date. It is my necessity that I query by order number only and for each order number, get the rest of the data for each listitem.

    Can you share your ideas please?
  • sarangasl · 4 weeks ago
    Nice !!!!!!!!

    Try this too,
    SharePoint Lists and more
  • cotswoldsbb · 4 hours ago
    Thank you thank you thank you. Ive been looking everywhere for this exact article.

    Good work..