SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am making a visual web part for sharepoint 2010. I have a SPFolder object and I want to get all items in it, but I want to sort it by a specific field. I want to do this by CAML query instead of using a view.

I am currently doing this by return library.GetItemsInFolder(library.DefaultView, folder);. It doesn't seem to contain a parameter for a CAML query.

Does anyone know how to do this?


share|improve this question
up vote 2 down vote accepted

You can use the SPQuery.

SPQuery Query = new SPQuery();
Query.Folder = SPFolder Object;
Query.Query =  "insert caml query here..."
SPListItemCollection collListItems = List.GetItems(oQuery);

I would suggest doing some reading first before implementing this if you haven't used Spquery before.... You may want to look into the row limits and view attributes properties...

share|improve this answer

Your Answer


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.