4

I know how to get items from a folder inside a list (example below)

CamlQuery caml = new CamlQuery();
caml.FolderServerRelativeUrl = "/folder/path";

But how do you get the items from just the top root folder? I don't want to get all items, but just from that top path before it goes into any folders.

2

In that case you don't need to specify CamlQuery.FolderServerRelativeUrl property at all. The following example demonstrates how to retrieve items of top folder in List:

var list = ctx.Web.Lists.GetByTitle(listTitle);
var items = list.GetItems(new CamlQuery());
ctx.Load(items);
ctx.ExecuteQuery();

If you are interested in returning only items associated with files then you could consider the following example:

var list = ctx.Web.Lists.GetByTitle(listTitle);
var items = list.GetItems(CreateItemsQuery());
ctx.Load(items);
ctx.ExecuteQuery();

where

public static CamlQuery CreateItemsQuery()
{
    return new CamlQuery()
    {
        ViewXml = "<View ><Query><Where><Eq><FieldRef Name=\"FSObjType\" /><Value Type=\"Integer\">0</Value></Eq></Where></Query>\r\n</View>"
    };
}
| improve this answer | |
1

You just need this:

SPQuery query = new SPQuery();
SPListItemCollection myItems = list.GetItems(query);

By default you get the files under the root folder.
Scopes in a CAML Query

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.