c# - InvalidRequest 在驱动器之间移动 DriveItem
问题描述
我正在尝试将DriveItem
位于父 SharePoint 网站的根驱动器中的一个移动到子子网站。
父站点:
mydomain.sharepoint.com/sites/Graph
- 列表:文档
子站点
mydomain.sharepoint.com/sites/Graph/SubwebA
- 列表:文档
我正在使用 Microsoft Graph SDK v3.25.0:
var client = GetGraphClient();
var destDriveItem = new DriveItem
{
ParentReference = new ItemReference
{
DriveId = destDriveID,
Id = destDriveFolderID
}
};
var response = await client
.Drives[driveID]
.Items[sourceDriveItemID]
.Request()
.UpdateAsync(destDriveItem);
所有 ID 均有效,但UpdateAsync
返回此错误:
ServiceException: Code: invalidRequest
Message: Requested move requires an async response, add 'Prefer: respond-async' to allow
Inner error:
AdditionalData:
date: 2021-03-04T15:44:38
request-id: 2aa656e2-fc4b-4314-846b-b62680a15ece
client-request-id: 2aa656e2-fc4b-4314-846b-b62680a15ece
ClientRequestId: 2aa656e2-fc4b-4314-846b-b62680a15ece
at Microsoft.Graph.HttpProvider.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
at Microsoft.Graph.BaseRequest.SendRequestAsync(Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption)
at Microsoft.Graph.BaseRequest.SendAsync[T](Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption)
at Microsoft.Graph.DriveItemRequest.UpdateAsync(DriveItem driveItemToUpdate, CancellationToken cancellationToken)
at GraphToM365Test.Program.MoveDriveItemToDestinationAndBack(String sourceDriveItemId) in C:\Dev\StratusApps\GraphToM365Test\GraphToM365Test\Program.cs:line 166
at GraphToM365Test.Program.MainAsync(String[] args) in C:\Dev\StratusApps\GraphToM365Test\GraphToM365Test\Program.cs:line 62
如果我在同一站点中移动DriveItem
两个(文档库)之间的代码,则相同的代码可以工作。Drives
该问题可能与此GitHub 问题有关(尽管这是为了在同一站点中移动)
解决方案
这是不受支持的操作。从文档中:
无法使用此请求在驱动器之间移动项目。
相反,您需要拨打两个电话:
var client = GetGraphClient();
var parentReference = new ItemReference
{
DriveId = destDriveID,
Id = destDriveFolderID
};
var copyResponse = await client
.Drives[driveID]
.Items[sourceDriveItemID]
.Copy(name, parentReference)
.Request()
.PostAsync();
var deleteResponse = await client
.Drives[driveID]
.Items[sourceDriveItemID]
.Request()
.DeleteAsync();
推荐阅读
- arrays - 为什么我不能分隔字符串中的字母?
- powershell - 通过 Selenium Powershell 单击按钮
- vue.js - 当我将其设置为 v-for 时,我无法访问我的 ref
- swift - 在光线追踪有效载荷中存储“ray_data”
- java - 使用 Postman 进行 GWT HTTP Post 测试
- ubuntu - 了解 tcpdump 的 ip packet payload 输出
- visual-studio - Visual Studio 2019 颜色主题无法像以前的版本那样工作
- azure-pipelines - 扩展和包含的 Azure 管道模板之间的功能比较
- ios - 从不同线程到达领域结果对象会导致崩溃
- java - 如何使 Sonar 符合 XMLInputFactory 和 woodstox 库的注册实现?