1

I'm trying to delete a file in a document library (SharePoint online) via the Graph SDK

await client
    .Drives[driveId]
    .Items[sourceItemId]
    .Request()
    .DeleteAsync();

This work. But if the file is open it'll throw this error:

Status Code: Locked
Microsoft.Graph.ServiceException: Code: resourceLocked
Message: The resource you are attempting to access is locked

How do I force it to delete anyway?

If I try to delete the open file via the SharePoint online UI (browser) then I get a popup saying it's locked but I can choose to delete it anyway. So deleting locked/open files is possible. They just forgot to document it here https://learn.microsoft.com/en-us/graph/api/driveitem-delete?view=graph-rest-1.0&tabs=csharp

2
  • I would suggest you to file the above as an uservoice with Microsoft Graph OneDrive team. So that they can consider implementing this as a new feature. Here's the closest uservoice that i remember - microsoftgraph.uservoice.com/forums/… Commented Nov 4, 2020 at 16:30
  • 1
    Being said that i remember an related SO thread in the samelines, let me share it here - stackoverflow.com/questions/61554807/… Commented Nov 4, 2020 at 16:31

1 Answer 1

0

I was also using graph SDK to perform the same action, but haven't found any useful thread to remove/ignore the existing file lock. Then I found one method named DeleteWithParameters() under Microsoft.SharePoint.Client.File class, which accepts one parameter of type FileDeleteParameters through which we can set BypassSharedLock parameter as true to bypass the existing lock. The code will be like the following:

 Microsoft.SharePoint.Client.FileDeleteParameters fileParams = new Microsoft.SharePoint.Client.FileDeleteParameters();
 fileParams.BypassSharedLock = true;
 var testDocument = clientContext.Web.GetFileByServerRelativeUrl(uri.LocalPath);
 testDocument.DeleteWithParameters(fileParams);
 clientContext.ExecuteQuery();

For your reference :

enter image description here

Please note: I know this is not answering the exact question, since the OP is asked for an option to remove/ignore the lock using graph SDK. But still, others can use this approach since it's a part of Microsoft.SharePoint.Client not any external sdk.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.