c# - C# SharePoint 异常“Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException”当 GetFileByServerRelativeURL
问题描述
我得到了PropertyException
这段代码的第二部分。第一部分按预期上传文件。之后context.ExecuteQuery();
我得到:
“uploadedFile.CheckInComment”引发了“Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException”类型的异常
我不确定为什么上下文应该没问题,因为它确实上传了文件。
我将尝试更新我刚刚上传的文档上的一些元数据字段。
Folder currentRunFolder = site.GetFolderByServerRelativeUrl(barRootFolderRelativeUrl + "/");
FileCreationInformation newFile = new FileCreationInformation
{
Content = System.IO.File.ReadAllBytes(@p),
Url = Path.GetFileName(@p),
Overwrite = true
};
currentRunFolder.Files.Add(newFile);
currentRunFolder.Update();
context.ExecuteQuery();
newUrl = siteUrl + barRootFolderRelativeUrl + "/" + Path.GetFileName(@p);
// Set document properties
Microsoft.SharePoint.Client.File uploadedFile = context.Web.GetFileByServerRelativeUrl(newUrl);
ListItem listItem = uploadedFile.ListItemAllFields;
listItem["TestEQCode"] = "387074";
listItem.Update();
context.ExecuteQuery();
解决方案
好的,即使 ListItems 为 NULL,我也可以设置 TestEQCode 并进行更新,并且该字段正在 SharePoint 端进行更新。一直以来,我都在关注 ListItems 获取实际元数据列表,但实际上它并不需要。我只需要对这些项目进行硬编码,它就会更新。–
推荐阅读
- r - pddl 错误:持续动作声明中的语法错误
- php - Symfony easyadmin ERR_TOO_MANY_REDIRECTS 在生产服务器上
- javascript - 如何在不关闭 JavaScript 页面的情况下单击空格来暂停视频
- c# - 为每个页面共享 ViewModel 数据,同时为不同的视图重用单个 ViewModel
- javascript - 我在 javascript 中的基本项目有问题
- python - 改变数据框,就像每一行只包含一个值,其余为 0
- authentication - 将一个 keycloak 领域设置为其他 keycloak 领域的 Idp
- algorithm - 如何检查算法范式是否可以解决某种类型的问题?
- python - 在 Python 中分隔坐标列表时出错
- google-apps-script - 根据单元格中的数据保护行(是/否)