[英]Delete locked/open file via Graph API/SDK
I'm trying to delete a file in a document library (SharePoint online) via the Graph SDK我正在尝试通过 Graph SDK 删除文档库(SharePoint Online)中的文件
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.如果我尝试通过 SharePoint 在线用户界面(浏览器)删除打开的文件,则会出现一个弹出窗口,提示它已被锁定,但我仍然可以选择删除它。 So deleting locked/open files is possible.因此可以删除锁定/打开的文件。 They just forgot to document it here https://docs.microsoft.com/en-us/graph/api/driveitem-delete?view=graph-rest-1.0&tabs=csharp他们只是忘了在这里记录它https://docs.microsoft.com/en-us/graph/api/driveitem-delete?view=graph-rest-1.0&tabs=csharp
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.我也使用图形 SDK 来执行相同的操作,但还没有找到任何有用的线程来删除/忽略现有的文件锁。 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.然后我在Microsoft.SharePoint.Client.File
类下找到了一个名为DeleteWithParameters()
方法,该方法接受一个FileDeleteParameters
类型的参数,我们可以通过该参数将BypassSharedLock
参数设置为 true 以绕过现有锁。 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 :供你参考 :
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.请注意:我知道这并没有回答确切的问题,因为要求 OP 提供使用图形 SDK 删除/忽略锁定的选项。 But still, others can use this approach since it's a part of Microsoft.SharePoint.Client
not any external sdk.但是,其他人仍然可以使用这种方法,因为它是Microsoft.SharePoint.Client
的一部分,而不是任何外部 sdk。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.