Pregunta

I have the following CAML query where i am trying to get all the files and folders that are directly and indirectly added to the folder named FolderA:-

camlQuery6.ViewXml = "<View Scope=\"RecursiveAll\"><Query><Where><Eq><FieldRef Name=\"FileDirRef\" /><Value Type=\"Text\">" + context.Web.ServerRelativeUrl + "/ArchDocs/FolderA"</Value></Eq></Where></Query></View>";
ListItemCollection collListItem6 = context.Web.GetList(context.Web.ServerRelativeUrl + "/ArchDocs").GetItems(camlQuery6);
context.Load(collListItem6, items => items.Include(
      item => item.Id,
      item=>item["FileDirRef"],
      item => item["Title"],
      item => item["DealStage"]));

the above CAML will only return the main folder under /sites/projects/ArchDocs/FolderA, but will not return any of the sub-folders and files.. so can anyone advice how i need to modify the CAML, or CAML does not support this?

¿Fue útil?

Solución

The query is only returning items directly in that folder because your CAML is set to only return items where the FileDirRef (or Folder Path) is equal to /sites/projects/ArchDocs/FolderA, anything that is in a subfolder would have a different FileDirRef, such as /sites/projects/ArchDocs/FolderA/SubFolder1, which would not be equal to the path you specified. What you want to do, is instead of the <Eq> operator element, you want to use <BeginsWith>. Note, you also appear to have syntax error with your string concatenation context.Web.ServerRelativeUrl + "/ArchDocs/FolderA"</Value>

Give this a try:

camlQuery6.ViewXml = "<View Scope=\"RecursiveAll\"><Query><Where><BeginsWith><FieldRef Name=\"FileDirRef\" /><Value Type=\"Text\">" + context.Web.ServerRelativeUrl + "/ArchDocs/FolderA" + "</Value></BeginsWith></Where></Query></View>";
ListItemCollection collListItem6 = context.Web.GetList(context.Web.ServerRelativeUrl + "/ArchDocs").GetItems(camlQuery6);
context.Load(collListItem6, items => items.Include(
      item => item.Id,
      item=>item["FileDirRef"],
      item => item["Title"],
      item => item["DealStage"]));
Licenciado bajo: CC-BY-SA con atribución
scroll top