Get "Value does not fall within the expected range." when try to list doc library folder file contents
-
Wednesday, May 16, 2012 10:09 PM
When I use the code below I get the error message "Value does not fall within the expected range." I am using the Microsoft.SharePoint.Client.
CamlQuery query = new CamlQuery();
query.ViewXML = "<View Scope='RecursiveAll' />";
query.FolderServerRelativeUrl = "/mysubfolder";
ListItemCollection listItems = spList.GetItems(query);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
Thanks for any help.
Rich
Rich Stewart
All Replies
-
Thursday, May 17, 2012 1:28 AM
Make sure to include the url name of the list in the FolderServerRelativeUrl property, for example query.FolderServerRelativeUrl = "/listname/mysubfolder"
Working example:
public static void GetListItemsInFolder() { ClientContext clientContext = new ClientContext("http://basesmc2008"); List list = clientContext.Web.Lists.GetByTitle("tester2"); CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = @"<View Scope='Recursive'> <Query> </Query> </View>"; camlQuery.FolderServerRelativeUrl = "/tester2/whatdown"; ListItemCollection listItems = list.GetItems(camlQuery); clientContext.Load(listItems); clientContext.ExecuteQuery(); ListItem itemOfInterest = listItems[0]; string creator = itemOfInterest.FieldValues["Created_x0020_By"].ToString(); string title = itemOfInterest.FieldValues["Title"].ToString(); }Blog | SharePoint Field Notes Dev Tool | ClassMaster
-
Thursday, May 17, 2012 6:31 PM
Steve,
Thanks for the response. Unfortunately, the code below, which is exactly what I'm using, still gives the same error.
Rich
Rich Stewart
-
Thursday, May 17, 2012 7:19 PM
Have you tried url encoding the string, for instance try "/Enterprise%20Project%20Information/Active%20Project%20Status%20Reports". The title of a list is not necessarily the Url of the list. Titles can be changed and can be different than the Url.
Blog | SharePoint Field Notes Dev Tool | ClassMaster
-
Thursday, May 17, 2012 8:44 PMYes, I tried url encoding the string. It didn't make a difference. I also tried the code on another document library in another site and got the same result.
Rich Stewart
-
Thursday, May 17, 2012 9:49 PM
I resolved this problem by changing the FolderServerRelativeUrl property to "/employee/project/Enterprise Project Information/Active Project Status Reports". I hadn't realized the need to include everything after https://...com.Rich Stewart
- Marked As Answer by Xue-Mei Chang-MSFTModerator Wednesday, May 23, 2012 3:15 AM
-
Thursday, May 17, 2012 10:01 PMGreat. I was working from a root site so I only had to include the list name. Good to know.
Blog | SharePoint Field Notes Dev Tool | ClassMaster

