Free Support Forum -

Saving a document in read only mode


We are using Aspose component to manipulate word document from windows application and we need to save these document as read only after replacing bookmark in that document, below is a code snippet to give some idea. We need to mark this file attribute as read only once we save this document so that in the next line when we open that document explicitly using Process.Start it should be in read only mode when user view that. tried document

doc.ViewOptions.ViewType =ViewType.Reading;

doc.Protect(ProtectionType.ReadOnly); but not achive the task.

//here is the code

Document doc = new Document(templateFileName);

doc.Range.Replace(new Regex(" "), new ReplaceEvaluator(ReplaceBookmark), false);

doc.Save(outfileDirectory + "BookmarkExample2.doc");

//Document doc1 = new Document(outfileDirectory + "BookmarkExample Out.doc");

doc.ViewOptions.ViewType =ViewType.Reading;


Process.Start(outfileDirectory + "BookmarkExample2.doc");


Thanks for your request. If you save and open the document using the following code then it will be opened in read only mode.




Also, note that ViewType is the option that sets how to show the document in MSWord.

Best regards.