如何通过 Graph API/SDK 检查文件是否锁定/打开

发布于 2025-01-17 20:23:08 字数 785 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

徒留西风 2025-01-24 20:23:10

我们找到的解决方案是制作并传递一个绕过共享锁的 HeaderOption,然后将其添加到请求中。这会绕过锁定文件 423 错误响应。并允许graphServiceClient删除文件,无论文件是否打开。

List<Microsoft.Graph.Option> reqOptions = new List<Microsoft.Graph.Option>
    {
        new Microsoft.Graph.HeaderOption("Prefer", "bypass-shared-lock")
    };

await graphServiceClient.Groups[groupId].Drive.Items[driveItem.Id].Request(reqOptions).DeleteAsync();

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.

List<Microsoft.Graph.Option> reqOptions = new List<Microsoft.Graph.Option>
    {
        new Microsoft.Graph.HeaderOption("Prefer", "bypass-shared-lock")
    };

await graphServiceClient.Groups[groupId].Drive.Items[driveItem.Id].Request(reqOptions).DeleteAsync();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文