0

1.This is the behavior I am observing when I use Update DriveItem graph API to update my file name.https://learn.microsoft.com/en-us/graph/api/driveitem-update?view=graph-rest-1.0&tabs=http.

2.If the file is open in my office desktop document it throws locked exception. If i close the file renaming works fine.

3.I tested same in sharepoint their UI ,I am able to rename the file.But through graph API it throws locked exception if file is open.

Is this error expected ?. How can I get around this

https://learn.microsoft.com/en-us/graph/api/driveitem-update?view=graph-rest-1.0&tabs=http.
PATCH https://graph.microsoft.com/v1.0/drives/b!qnfox2pppU-AeWEPhWpRhNiB9gIq_ANJq5NFCiklU2Y5F3fDc7fsaQvB/items/014UHAXWYO5LX2RTA6YZE37E4XTG45PTTW
SdkVersion : graph-java/v1.6.0
Authorization : Bearer
{"name":"V-blah (1) (113_0_4_26).docx"}

423 : Locked
Strict-Transport-Security : max-age=31536000
Cache-Control : private
x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"West US","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_57"}}
client-request-id : 33f16bde-55d1-XXXX
request-id : XXXXXXX
Content-Length : 251
Date : Sat, 02 May 2020 04:05:23 GMT
Content-Type : application/json
{
  "error": {
    "code": "resourceLocked",
    "message": "The resource you are attempting to access is locked",
    "innerError": {
      "request-id": "d1bfa1f2-cXXXXX",
      "date": "2020-05-02T04:05:23"
    }
  }
}
Shama
  • 55
  • 1
constantlearner
  • 5,157
  • 7
  • 42
  • 64

2 Answers2

2

Ensure that the document library does not have "check-in required" enabled.

Assuming check-in is not required, I received the same HTTP 423 "resourceLocked" response for both scenarios: file opened in the browser (SharePoint Online UI) and file opened in desktop client. I believe this is working by design that you can't update a file's name when it is currently opened by another user or yourself in another instance.

Please see this reference about files locked for editing.

  • I am getting the error with subsequent API calls. I.e. if I POST to create a new file and afterwards PATCH to make an update to its metadata (e.g. updating custom column/field values of the item) this exception is thrown. No client desktop/mobile/web has opened the file. – baouss Nov 22 '21 at 21:21
0

Try adding the HeaderOption that bypasses the shared lock, to the request.

new Microsoft.Graph.HeaderOption("Prefer", "bypass-shared-lock")

If you are using the graphServiceClient, add it to a List and pass it directly in your Request.

jjirinec
  • 1
  • 1