c# - 如何更新 Sharepoint CSOM 中的文件元数据?
问题描述
我知道过去曾有人问过这个问题,但我似乎找不到可行的解决方案。我想更新我使用 CSOM 上传的文件的 CreatedDateTime、ModifiedBy 和 CreatedBy 元数据。我有这个代码。它不会崩溃,但也不会更新属性。
FileCreationInformation newFile = new FileCreationInformation();
byte[] FileContent = null;
using (var webClient = new WebClient())
{
webClient.Headers.Add("Authorization", authorization);
FileContent = webClient.DownloadData(file.DowlnloadUrl);
}
newFile.ContentStream = new System.IO.MemoryStream(FileContent);
newFile.Url = System.IO.Path.GetFileName(file.Name);
Microsoft.SharePoint.Client.File sharepointFile = _spFolder.Files.Add(newFile);
_context.ExecuteQuery();
sharepointFile.ListItemAllFields["Modified"] = DateTime.Today.AddDays(-3);
sharepointFile.ListItemAllFields["Created"] = DateTime.Today.AddDays(-3);
sharepointFile.ListItemAllFields.Update();
_context.ExecuteQuery();
任何帮助,将不胜感激。PS:如果这可以一次性完成(一个单一的 ExecuteQuery),那就太好了。
解决方案
我最终找到了一个有效的代码片段。请注意,这仅在您用于生成上下文的帐户是Sharepoint 管理员(具有 SP 管理员角色,而不仅仅是全局管理员角色)时才有效。成为该网站的所有者也是不够的。
推荐阅读
- javascript - 如何扩充现有函数,使其懒惰地解开其参数?
- javascript - 为什么此警报显示“未定义”而不是当前月份的值?
- c# - 聚合根 DDD/UoW/Repo/Service
- javascript - 哪种注释格式对于带有注释的 TypeScript 是正确的?
- android - 将 Android.mk 中的共享库包含到 Android.bp 的 cc_test 中
- javascript - AngularJS 指令表达式绑定与 `"&"` 函数和参数
- django - Django JsonField 数组数据查询
- python - 我已经安装了 pyinstaller,但它不会运行
- eclipse - Eclipse 中缺少服务器适配器的配置文件
- powerbi-embedded - PowerBI Embedded 不使用 AD 使用来自 AAS 的数据