Monday, May 23, 2016

Delete folders in a document library using CSOM

            ClientContext clientContext = new SP.ClientContext.get_current();
            List docLib = clientContext.Web.Lists.GetByTitle(<LIBRARY NAME>);
            CamlQuery camlQuery = new CamlQuery();
            camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='FSObjType' />"
                + "<Value Type='Integer'>1</Value></Eq></Where></Query></View>";
            ListItemCollection items = docLib.GetItems(camlQuery);
            clientContext.Load(items);
            clientContext.ExecuteQuery();
            foreach (var item in items)
            {
                items.GetById(item.Id).DeleteObject();
                clientContext.ExecuteQuery();
            }

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...