3

We are developing a web application that will provide some WebDAV features and to implement these we are evaluating the IT-Hit server engine component for .NET.

The aim is to give the user a certain MS Office document in read-write or read-only mode based on some internal logic; we have tried to investigated through the WebDAV template application in Visual Studio and through the online documentation, but we haven't found a specific method to accomplish this. Where could we find more specific references?

Moreover, is it possible to know when an user has closed the MS Office application (i.e. MS Word) and completed his/her interaction with the document?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118

1 Answers1

0

To make a file read-only you can implement IMsItem interface on file items. Your IMsItem.GetFileAttributes method implementation must return read-only attribute for a file:

public FileAttributes GetFileAttributes()
{
    ...
    if(/*this file is read-only*/)
    {
         return fileSystemInfo.Attributes | FileAttributes.ReadOnly;
    }
    ...
}

Note that this code does not actually protects file from modification, it only marks the file as read-only. If application ignores read-only flag it may be able to overwrite the file. To make sure this does not happen, in your IFile.Write method implementation you must verify if user has rights to modify the file and the file is not read-only. If the file is read-only - throw the exception.

Microsoft Office locks file when opening and unlocks when closing. So when the file is closed the ILock.Unlock() method is called on the server side. Note that in case the connection is lost and the file is not unlocked by MS Office your server implementation usually you will unlock the file automatically after lock expires.

Please also read about how WebDAV locking works here.

IT Hit WebDAV
  • 5,652
  • 12
  • 61
  • 98
  • Thanks for the inputs. I'd have just one more question about the read only mode: you said "Note that this code does not actually protects file from modification, it only marks the file as read-only. If application ignores read-only flag it may be able to overwrite the file." Does it means that there is no chances to open the file into client MS Word with "Read only" tag? Through the IMsItem I'm now able to see the "Read only" attribute in the Windows Explorer, but Word opens the file without any warning. – Michele Negri Mar 04 '13 at 11:43
  • @MicheleNegri: did you solve this? I have the same problem with Excel, Excel doesn't seem to pay attention to the readonly flag. As per the suggestion in the reply I checked my conditions in the IContent.Write method implemented by DavFile. I am also contemplating the idea of artificially locking the file... – boggy Jun 04 '13 at 23:42
  • The FileAttribute gets completely ignored. Word opens in edit mode anyway. Is there any other way to accomplish this? – greenhoorn Jun 22 '17 at 07:36