我想从sharepoint 2010
服务器读取一些文件夹和文件属性。最重要的属性是 UniqueId 。有可能读取该属性吗?
我尝试使用CSOM(Microsoft.SharePoint.Client.dll)。这对于下面用于Sharepoint 2013及更高版本的代码很好用。它适用于Sharepoint在线和Sharepoint服务器。问题是我需要阅读的Sharepoint 2010服务器。发生类似
的异常字段或属性UniqueId不可用。
ListItemAllFields
也不可用。我读了很多帖子,但找不到解决方案。
我可以确定通常会有3种解决方案:
我了解了 Caml查询,发现了类似<FieldRef Name='UniqueId'/>
的内容,但我不知道如何使用它,也不知道是否甚至可以读取UniqueId。 / p>
以下代码在sharepoint 2013
及更高版本上正常运行,但不适用于sharepoint 2010
服务器:
public string GetChilds(ClientContext clientContext, string relativeUrl)
{
SpFolder folder =clientContext.Web.GetFolderByServerRelativeUrl(relativeUrl);
clientContext.Load(folder,
item => item.Name,
item => item.UniqueId,
item => item.ServerRelativeUrl
);
clientContext.Load(folder.Folders,
items => items.Include(
item => item.Name,
item => item.UniqueId,
item => item.ServerRelativeUrl,
item => item.TimeLastModified,
item => item.TimeCreated,
item => item.ListItemAllFields["Author"],
item => item.ListItemAllFields["Editor"]));
clientContext.Load(folder.Files,
items => items.Include(
item => item.Name,
item => item.UniqueId,
item => item.ServerRelativeUrl,
item => item.TimeLastModified,
item => item.TimeCreated,
item => item.ListItemAllFields["Author"],
item => item.ListItemAllFields["Editor"],
item => item.ListItemAllFields["File_x0020_Size"]));
clientContext.ExecuteQueryWithIncrementalRetry(EXECUTEQUERY_RETRYCOUNT, EXECUTEQUERY_DELAY);
string result = "";
result += "Parent Name:" + folder.Name + ",";
result += "Parent UniqeId:" + folder.UniqueId.ToString() + ",";
result += "Parent ServerRelativeUrl:" + folder.ServerRelativeUrl + ",";
if (folder.Folders != null)
{
foreach (SpFolder subFolder in folder.Folders)
{
result += "Name:" + subFolder.Name + ",";
result += "UniqueId:" + subFolder.UniqueId.ToString() + ",";
//...
}
}
if (folder.Files != null)
{
foreach (SpFile file in folder.Files)
{
result += "Name:" + file.Name + ",";
result += "UniqueId:" + file.UniqueId.ToString() + ",";
//...
}
}
return result;
}
预期结果将是从Sharepoint 2010服务器检索UniqueId
和ListItemAllFields
。
实际结果是:
字段或属性的UniqueId不可用
答案 0 :(得分:0)
我们在SharePoint 2010
上遇到了完全相同的问题。
它使用CSOM
通过这种方式为我们工作:
File file = ClientContext.Web.GetFileByServerRelativeUrl(docUrl);
ClientContext.Load(file, f => f.ListItemAllFields);
ClientContext.ExecuteQuery();
ListItem item = file.ListItemAllFields;
string fileName = item.FieldValues["FileLeafRef"].ToString();
string fileType = System.IO.Path.GetExtension(FileName);
var furl = item.FieldValues["_dlc_DocIdUrl"] as FieldUrlValue;
string documentPermalinkUrl = furl.Url;
Guid uniqueId = new Guid(item.FieldValues["UniqueId"].ToString());