mahboub_mo
mahboub_mo

Reputation: 3038

How to Determine If a Word Document Is Read-Only?

I use Word.Interop to work with Word Document and let user to open a file from hard disk.

Sometimes I get error saying that the file that user has chosen is readonly.

How can I check if a file is readonly or not?

Upvotes: 3

Views: 3018

Answers (1)

Adam
Adam

Reputation: 15803

Are you sure you are actually talking about the File attribute (that can be set via the Windows file properties dialog)? If so, you can use FileInfo.IsReadOnly:

FileInfo fileInfo = new FileInfo(@"path\to\file");
if (fileInfo.IsReadOnly)
{
    // do something
}

otherwise, refer to this answer if another process is using the file.

Upvotes: 7

Related Questions