1
votes

I'm using the Microsoft.Office.Interop.Word to manipulate the documents, things like creating a new document based on a template.

The only problem I'm having is to set the active document in Word to readonly. Keeping in mind that I open a new document based on a template, fill some fields with the necessary information, then a need to show this document to the user as readonly. This document still in memory (Doesn't have a path).

The library have a readonly attribute, but is readonly (Oh the irony...). Anybody have any suggestions that might help me?

1
Once you've created the document and filled in the necessary fields, save it. Then reopen it as readonly and show to the user.NotMe
@ChrisLively I tried that solution and it worked, but I wish to implement something without using this method. Something more dynamic.Albert
Unless word can "open" a document that's already in memory there really isn't another way.NotMe

1 Answers

1
votes

Read-only is one of the defining features of the Document and thus it has to be set when the Document is created (added to the Application). Sample code:

bool readOnly = true;
Object templatePath = @"Path";
Object oMissing = System.Reflection.Missing.Value;
Word.Application wordApp = new Word.Application();
Word.Document wordDoc = wordApp.Documents.Open(templatePath, oMissing, readOnly, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);