4

I'm creating a solution for managing remote MS Office documents. I used library made by IT Hit WebDAV System (www.webdavsystem.com) as a prototype. It's doing pretty well actually, except I cannot open document in read-only mode using URIs for office (based on Office URI Schemes by Microsoft).

I want to open the document in read-only mode, so someone else can edit it in the same time. As it can be seen in B-3. URI Scheme Syntax part of mentioned documentation, there are three commands available:

  • ofe - open for edit
  • ofv - open for view
  • nft - new from template

It seems that server acts always as "ofe" commands was given, no matter which one was used. Actually, entering "whatever" also works, it can be literally everything. Using MS Word for example, I post request order below:

OPTIONS => HEAD => OPTIONS => OPTIONS => LOCK => GET => PROPFIND => OPTIONS

As I am understanding correctly, successful LOCK attempt results in opening the document in edit mode. That tells me, that somewhere before that point MS WORD should ask for permission to do it, but I analyzed previous requests and was unable to find any related data.
It is not my environment issue also. I checked it with SharePoint and it was ok. That's why I would blame the server.

As I read that sentence(below) in this question,

most WebDAV clients ignore this and pretend that the entire server is either read-write or read-only

I started to wonder. Maybe that's the case? Maybe the library skips that and treats every file as read-write? If yes, how can I check it to be sure?

I've checked also this topic. The author mentions, that he has Office URI command in his OPTIONS requests, but links are no longer valid. In the requests that are sent by MS Office 2016, I can't find it anywhere. Should it be anywhere? Where?

Last, but not least, I found this topic. It seems to be exactly my problem, but it don't have the solution mentioned, or at least anything that worked in my case.

I will appreciate any help.

Mike Sar
  • 107
  • 9
  • For me completely removing both DAV header as well as MS-Author-Via: DAV for read only files worked very well. I assume that might not be suitable for all cases (e.g. when some other WebDAV features are needed). – Marcin Pieciukiewicz May 14 '21 at 11:09

1 Answers1

3

We have recently retested ofv and ofe options with latest MS Office 2016 for Windows and for Mac OS X with all updates installed. Here is what we have found:

  • On Windows this option is being ignored. Regardless of this parameter MS Office opens as read-write.
  • On Mac OS this option is required. MS Office respects this option and opens depending on ofv/ofe as read-only or read-write.

From our experience there is no reliable way to open a document as read-only. In SharePoint Online (SPS 2016) there is also no option to open a document as read-only in the desktop version of MS Office.

One workaround could be throwing DavException in IFileAsync.WriteAsync() method implementation when saving a file. Please note that MS Office will ignore the message text being returned and will just display a generic error.

Another workaround would be marking a document as read-only in IMsItemAsync.GetFileAttributesAsync() method implementation:

    public async Task<FileAttributes> GetFileAttributesAsync()
    {
        return fileSystemInfo.Attributes | FileAttributes.ReadOnly;
    }

MS Office will display a yellow ribbon "UPLOAD FAILED This file is locked for editing by another user".

IT Hit WebDAV
  • 5,652
  • 12
  • 61
  • 98
  • Thanks, got the same problem on windows. Even failed LOCK query can't stop MS Word to open documents read-write. – Pavel Aug 01 '19 at 07:04
  • One of the solutions might be _not_ to include 'MS-Author-Via' header in OPTIONS response. From my experience this makes Word to open in read only mode. – Marcin Pieciukiewicz Jul 09 '20 at 10:09