Is there a way to get the json content of files fetched through a CAML query?
-
08-02-2021 - |
Frage
const query = `<Where>
<Eq><FieldRef Name="File_x0020_Type"/>
<Value Type="Text">json</Value>
</Eq>
</Where>`;
const xml = '<View Scope="RecursiveAll"><Query>' + query + '</Query></View>';
const result = sp.web.lists.getByTitle('myassets').getItemsByCAMLQuery({'ViewXml':xml}).then((res:any).then((res:any) => { return res; })
Used the CAML query above to fetch files, but I can't get the json content of the files. I looked at the json returned and I don't see anything relating to the content of the files. Is there a way to get the content of several files fetched through CAML? I know there's a PnP method to fetch an individual json, but I need to get the json of every file fetched at once.
Lösung
Sample demo:
const query = `<Where>
<Eq><FieldRef Name="File_x0020_Type"/>
<Value Type="Text">json</Value>
</Eq>
</Where>`;
const xml = '<View Scope="RecursiveAll"><Query>' + query + '</Query></View>';
sp.web.lists.getByTitle('MyDoc2').getItemsByCAMLQuery({'ViewXml':xml},'FileRef').then((items:any) => {
items.map((item)=>{
console.log(item);
sp.web.getFileByServerRelativeUrl(item.FileRef).getJSON().then((data)=>{
console.log(data);
})
})
})
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit sharepoint.stackexchange