0

I want to get particular folder or subfolders items only on demand, not all recursive.

My code so far:

        private static void GetListItems(string relativeUrl)
    {
        var context = new ClientContext("siteUrl");
        var list = context.Web.Lists.GetByTitle(docListName);

        var viewXml = "<View" +
                      "<Query>" +
                      "<Where>" +
                      "<Eq>" +
                      "<FieldRef Name=\"FileDirRef\" />" +
                      "<Value Type=\"Text\">" + relativeUrl + "</Value>" +
                      "</Eq>" +
                      "</Where>" +
                      "</Query>" +
                      "</View>";

        var query = new CamlQuery { ViewXml = viewXml, FolderServerRelativeUrl = relativeUrl };

        var items = list.GetItems(query);

        context.Load(items, c => c.Include(
            i => i.Id,
            i => i.DisplayName,
            i => i.FileSystemObjectType,
            i => i.Folder,
            i => i.File,
            i => i["FileDirRef"],
            i => i["FileRef"],
            i => i["FileLeafRef"]));

        context.ExecuteQuery();

        foreach (var i in items)
        {
            Console.WriteLine($"{i.Id} {i.DisplayName}");
        }
    }

The problem is that i always get first level items only no matter what relative server url i passing as parameter.

Your Answer

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

Browse other questions tagged or ask your own question.