0
我想要使用CSOM为1个特定文件检索1列,这些可以位于任何位置,因此可以在任何文件夹类型的内容类型(包括文档集)中找到。caml查询来查询包含文档集内的文件
因此,我可以先检查,然后...如果结果= 0,然后遍历文件夹,看看排队的父母是否是文档集...然后再进行检查,但我想知道如果没有查询了更加便利的方式
下面的代码工作,但“无论是在lib和内容类型中,如文档,只要它是一个文件中设置” ....如果该文件将无法正常工作在文件集内。
var baseUrl = uri.GetLeftPart(UriPartial.Authority);
var fileServerRelativeUrl = uri.ToString().Replace(baseUrl, string.Empty);
logger.Log(LogLevel.Debug, " fileserverrelativeurl is " + fileServerRelativeUrl.ToString());
var file = context.Web.GetFileByServerRelativeUrl(fileServerRelativeUrl);
List list = file.ListItemAllFields.ParentList;
context.Load(list);
context.ExecuteQuery();
logger.Log(LogLevel.Debug, " list is loaded: " + list.Title.ToString());
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml =
"<View><Query><Where><Eq><FieldRef Name='" + fieldRefName + "'/>" +
"<Value Type='Text'>" + fieldRefValue + "</Value></Eq></Where>" +
"<RowLimit>1</RowLimit></Query></View>";
logger.Log(LogLevel.Debug, " caml is " + camlQuery.ViewXml.ToString());
ListItemCollection listItems = list.GetItems(camlQuery);
context.Load(listItems);
try
{
context.ExecuteQuery();
}
catch
{
logger.Log(LogLevel.Debug, " caml exec FAILED !! ");
// e.g. : no access or the listname as incorrectly deduced
throw;
}
logger.Log(LogLevel.Debug, " items found: " + listItems.Count.ToString());
// and now retrieve the items needed
if (listItems.Count == 1)
{
logger.Log(LogLevel.Debug, " listitem found ");
ListItem item = listItems[0];
foreach (string column in columns)
{
if (item.FieldValues.ContainsKey(column))
{
logger.Log(LogLevel.Debug, " column found: " + column);
if (item[column] is Dictionary<string, object>)
{
Dictionary<string, object> clientTaxonomyObject = item[column] as
Dictionary<string, object>;
if (clientTaxonomyObject.ContainsKey("_ObjectType_") &&
clientTaxonomyObject.ContainsKey("TermGuid") &&
clientTaxonomyObject.ContainsKey("Label") &&
clientTaxonomyObject["_ObjectType_"].Equals("SP.Taxonomy.TaxonomyFieldValue"))
{
values.Add(column, clientTaxonomyObject["Label"].ToString());
}
else
{
values.Add(column, item[column].ToString());
}
}
else
{
values.Add(column, "");
}
}
}
}
}
裁判
- https://social.technet.microsoft.com/Forums/sharepoint/en-US/a83259c6-3667-47f8-83c9-da37aa1b6ead/caml-query-and-document-set
- Programmatically access files in Document set in sharepoint using Javascript
UPDATE
啊!更简单的是,不需要caml查询,只需要file.listitemallfields,然后只是抛弃该字段的分类标签。解决:)