Forum Discussion
Ricky Raghavan
Sep 11, 2018Copper Contributor
Using Node PNP JS How to check whether a folder exists in a Document Library
There are lot of examples on the Internet about checking whether a folder exists using CSOM. I did a lot of searching but couldn't find a good article that talks about doing this using PNP JS. I...
Saravanakumar Narayanan
Oct 03, 2019Copper Contributor
Ricky Raghavan hope this will help you., below code works for me.
public static getDocSetOrFolder(endPoint,listTitle,folerName):Promise<any>{
let web = new Web(endPoint);
const xml=this.returnCamlQueryToGetDocSetOrFolder(folerName);
const q: CamlQuery = {
ViewXml: xml,
};
return web.lists.getByTitle(listTitle).getItemsByCAMLQuery(q).then((docDetails)=>{
console.log("Folder details",docDetails);
return docDetails;
});
}
public static returnCamlQueryToGetDocSetOrFolder(folerName){
const viewXml =
"<View>" +
"<Query>" +
"<Where>" +
"<And>" +
"<Eq>" +
"<FieldRef Name=\"FSObjType\"/>" +
"<Value Type=\"Integer\">1</Value>" +
"</Eq>" +
"<Eq>" +
"<FieldRef Name=\"FileLeafRef\" />" +
"<Value Type=\"Text\">" + folerName + "</Value>" +
"</Eq>" +
"</And>" +
"</Where>" +
"</Query>" +
"<RowLimit>1</RowLimit>" +
"</View>";
return viewXml;
}