CSOM Caml查询返回列表文件夹子项

时间:2017-07-14 17:15:01

标签: sharepoint-2013 caml csom sharepoint-clientobject

我正在尝试仅返回给定列表文件夹的列表项。但是,每次执行以下操作时,我都会获得列表中的所有项目。仅获取SharePoint列表的特定文件夹的列表项的最简单方法是什么?

CamlQuery camlQuery = new CamlQuery
{
    ViewXml = "<View Scope=\'Recursive\' />",
    FolderServerRelativeUrl = "/Design Items"
};

ListItemCollection listItemCollection = list.GetItems(camlQuery);

我确定我是否需要FolderServerRelativeUrl属性中的列表名称,所以我尝试了以下

FolderServerRelativeUrl = "/[ListName]/Design Items"
FolderServerRelativeUrl = "/Lists/[ListName]/Design Items"

谢谢,

1 个答案:

答案 0 :(得分:1)

您需要提供完整的服务器相对URL。如果您的网站网址为https://contoso.com/sites/sitename/,那么它应该是

FolderServerRelativeUrl = "/sites/sitename/Lists/[ListName]/Design Items"

您还可以从ClientContext对象获取相对URL,如

 FolderServerRelativeUrl = ClientContext.Url+"/Lists/[ListName]/Design Items"