I have an SPFX application where the user can visualise a number of files stored in SharePoint. The files are open on an IFrame on the left that points to Office Online while the metadata are displayed on the right.

When the user edits the data the application calls a webservice where I modify the metadata of the files in the folder of the document using CSOM. But, because the file is open in Office Online in an IFrame, I get the following error :

'The file "Name of the file" is locked for shared use by User.'

is there a way to manually release the lock on a file opened by a user in Office Online using CSOM ? Or to open a file in office online in a way that it doesn't prevent the file from having its metadata modified ?

Here is the c# code :

        Web web1 = clientContext.Web;
        clientContext.Load(web1, wb => wb.ServerRelativeUrl);
        string path = incoming.SHPLinkedFolder.Replace(SiteUrl + "/", "");
        Folder folder = web1.GetFolderByServerRelativeUrl(path);

        foreach (File file in folder.Files)
            ListItem fileItem = file.ListItemAllFields;
            fileItem["Post_x0020_Stamp_x0020_Date"] = incoming.Post_Stamp_Date;
            fileItem["Reference_x0020_Letter_x0020_In"] = incoming.Reference_Letter_In;
            fileItem["Title"] = incoming.Title;
            fileItem["Document_x0020_Author"] = incoming.Document_Author;
            fileItem["Document_x0020_Language"] = incoming.Document_Language;
            fileItem["Document_x0020_Date"] = incoming.MailDate;

Thanks a lot for your time.

1 Answer 1


I have my fair share of locking situations and I thought to mention a few words. I work mainly with the on-premise model, but I believe this stays true for Online.

  • The lock exists because the document is open for editing

While you can look for ways to release the lock through CSOM (there used to be an old quirky way using RPC) the CSOM API itself does not have a method for that, even though it has been requested by many). The lock it just a symptom that something else is happening (i.e. document is open and in edit mode).

  • So what can do you?

a) not open the document at all (or close it before the edit)

b) open it in read-only mode. this may be a tough task in itself but some of these links provide potential solutions (e.g. open the view-only link to the document, set the library to require check out, etc.)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.