1

I am trying to get all files in a subfolder, in the Document Library "Shared Documents" in SP 2010.

So the structure looks like

http://sp2010site/sitename/shared documents/folder1/
http://sp2010site/sitename/shared documents/folder2/
http://sp2010site/sitename/shared documents/folder3/

I want to get all files under folder1, for example.

I need to use sp client object model unfortunately.

I keep getting a really unhelpful exception

"value does not fall within range"

any ideas how to get all files under Folder1?

//rootList is string "Shared Documents"

using (ClientContext ctx = new ClientContext(m_siteUrl))
            {
                List list = ctx.Web.Lists.GetByTitle(rootList);
                CamlQuery caml = new CamlQuery();
                caml.ViewXml = @"<View Scope='Recursive'>
                                    <Query>
                                    </Query>
                                </View>";
                caml.FolderServerRelativeUrl = "/Shared Documents/Folder1";
                ListItemCollection listItems = list.GetItems(caml);
                ctx.Load(listItems);
                ctx.ExecuteQuery(); //exception throws here

                ListItem itemOfInterest = listItems[0];
                string creator = itemOfInterest.FieldValues["Created_x0020_By"].ToString();
                string title = itemOfInterest.FieldValues["Title"].ToString();

EDIT:

I'm getting close

var folders = ctx.Web.Folders;
                ctx.Load(folders);
                ctx.ExecuteQuery();
                var theone = folders.Where(x => x.ServerRelativeUrl == "/sitename/Shared Documents");


// folders definetly loads and has all the folders, but I can't seem to do linq on it to just get the one I care about... WHY?

since i can't use LINQ i'm forced to do a foreach untill i find it...there must be a better way? because then once i've found the root folder (i.e. shared documents), i then need to loop through each subfolder in the same fashion... :-S

2

Since CamlQuery.FolderServerRelativeUrl property expects server relative URL of a list folder to be specified, try to specify it's value using the following format: /<WebRelativeUrl>/<ListUrl>/<FolderUrl>

Example:

caml.FolderServerRelativeUrl = "/sitename/Shared Documents/Folder1";

That will do the trick of getting list items from a specific folder.

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.