Saturday, June 25, 2016

Get folder item count using CSOM

ClientContext clientContext = new ClientContext(<SITEURL>)
List list = clientContext.Web.Lists.GetByTitle(<LIBRARYNAME>);
var query = new CamlQuery();
var folderServerRelativeUrl = "/sites/demo/Documents/Sample";
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();
Console.WriteLine(folderItems.Count);

No comments:

Post a Comment

How to launch a document by clicking a link to the file?

Word: <a href='ms-word:ofe|u|path/to/web/word/document.docx'>Link to document</a> Excel: <a href='ms-excel:o...