如何通过 Graph API/SDK 检查文件是否锁定/打开
I'm trying to delete a file in a document library (personal OneDrive) via the Graph SDK (using c#)
await graphClient.Drives[driveId].Items[driveItemId].Request().DeleteAsync();
It works.但是,如果文件打开,则会丢弃此错误:
423 : Locked
....
"error": {
"code": "resourceLocked",
"message": "The resource you are attempting to access is locked",
"innerError": {
"request-id": "d1bfa1f2-cXXXXX",
"date": "2020-05-02T04:05:23"
}
如果文件是通过Graph API/SDK锁定/打开的?)
我当前的解决方案是: 我会进行此调用,
await graphClient.Drives["{driveid}"].Items["{driveItemid}"].Checkout().Request().PostAsync();
如果文件打开, 我将与相同的423错误响应。然后,我要求用户关闭并重复。 如果我得到204个没有内容响应,请致电删除DriveItem。
但是我认为这不是一个优雅的问题。谢谢
I'm trying to delete a file in a document library (personal OneDrive) via the Graph SDK (using c#)
await graphClient.Drives[driveId].Items[driveItemId].Request().DeleteAsync();
It works. But if the file is open it'll throw this error:
423 : Locked
....
"error": {
"code": "resourceLocked",
"message": "The resource you are attempting to access is locked",
"innerError": {
"request-id": "d1bfa1f2-cXXXXX",
"date": "2020-05-02T04:05:23"
}
Is there any possibility to check if file is locked/open via Graph API/SDK?)
My current solution is:
i make this call
await graphClient.Drives["{driveid}"].Items["{driveItemid}"].Checkout().Request().PostAsync();
In case if file is open i ge t the same 423 error response. Then i ask user to make it close and repeat.
In case if i get 204 No content response i make call to delete driveItem.
But i do not think it is an elegant problem solving. Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们找到的解决方案是制作并传递一个绕过共享锁的 HeaderOption,然后将其添加到请求中。这会绕过锁定文件 423 错误响应。并允许graphServiceClient删除文件,无论文件是否打开。
The solution that we found was making and passing a HeaderOption that bypasses the shared lock, then adding it into the request. This bypasses the locked file 423 error response. And allows the graphServiceClient to delete the file regardless of whether it is open or not.