1

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

1 Answers1

0

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();
jjirinec
  • 1
  • 1