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.