SharePoint - Client Object Model - Get Subfolder Items

each 'listItem' contains elements, how to get them? I try for a while, but only fail,

help thanks

camlQuery from some tests and examples from the Internet didn't help (had a lot of changes)

ClientContext clientContext = new ClientContext("http://xxx.xxx.com"); List list = clientContext.Web.Lists.GetById(new Guid("{F91A0F26-2826-4B3B-AF30-ED7DE4494C7B}")); clientContext.Load(list); clientContext.ExecuteQuery(); CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = @"<queryOptions><QueryOptions><ViewAttributes Scope='RecursiveAll'/><Folder></Folder></QueryOptions></queryOptions>"; ListItemCollection listItems = list.GetItems(camlQuery); clientContext.Load(listItems); clientContext.ExecuteQuery(); foreach (ListItem listItem in listItems) { each lisItem has children/items , how to get them?! } 
+4
source share
3 answers

I found the answer, thanks for the helpers ... :) Items is my object that I created. to get the value of "folderServerRelativeUrl" you can get it from (string)listItem ["FileRef"] when you navigate the folders above foreach

  public Items GetFolderItems(string folderServerRelativeUrl, List list, ClientContext clientContext) { try { var result = new Items(); <-- my class var query = new CamlQuery(); query.FolderServerRelativeUrl = folderServerRelativeUrl; query.ViewXml = "<View Scope=\"RecursiveAll\"> " + "<Query>" + "<Where>" + "<Eq>" + "<FieldRef Name=\"FileDirRef\" />" + "<Value Type=\"Text\">" + folderServerRelativeUrl + "</Value>" + "</Eq>" + "</Where>" + "</Query>" + "</View>"; var folderItems = list.GetItems(query); clientContext.Load(folderItems); clientContext.ExecuteQuery(); foreach (ListItem item in folderItems) { // item[ "..." ]; } return result; } catch (Exception) { return null; } } 
+10
source

Another way to get all list items:

 camlQuery.ViewXml = @"<View Scope='RecursiveAll'> <Query> <Where> <Eq> <FieldRef Name='FSObjType' /> <Value Type='int'>0</Value> </Eq> </Where> </Query> </View>"; 
+3
source

Thanks for the great answer. To tell you that the folderServerRelativeUrl variable should be from the root Url (except for http://server ). I had a list called "Providers" inside the center document. That is, siteUrl is http://server/documentcenter , and the list name is Vendors. I had to pass "/ documentcenter / Vendors / ..." as my folder to ServerRelativeUrl. But it normal. I am grateful to you anyway.

People, so sad that I could not add a comment under his answer. I should have submitted this comment as an answer. Help me if it can be done differently. I do not want to edit his answer.

~ Sharmin

+1
source

Source: https://habr.com/ru/post/1397292/


All Articles