I am trying to Preview Word Documents in a RichTextBox. The code works fine, with the following two exceptions.
(1) When I open the file, I get the following Error Message Dialog:
File in Use
ABCFile.doc is locked for editing
by 'Username'
Click 'Notify to open a read-only copy of the document and
receive notification when the document is no longer in use.
The only one using this document is my program!
(2) Even though I have set appWord.Visible = false, Word still shows up.
C# Code:
Code:Word.ApplicationClass appWord; Word.Document docWord; Object filename = path; Object ConfirmConversions = System.Reflection.Missing.Value; Object ReadOnly = true; Object AddToRecentFiles = false; Object PasswordDocument = System.Reflection.Missing.Value; Object PasswordTemplate = System.Reflection.Missing.Value; Object Revert = System.Reflection.Missing.Value; Object WritePasswordDocument = System.Reflection.Missing.Value; Object WritePasswordTemplate = System.Reflection.Missing.Value; Object Format = System.Reflection.Missing.Value; Object Encoding = System.Reflection.Missing.Value; Object Visible = false; Object saveChanges = false; Object originalFormat = null; Object routeDoc = null; appWord = new Word.ApplicationClass(); appWord.Visible = false; docWord = appWord.Documents.Open(ref filename, ref ConfirmConversions, ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate, ref Revert, ref WritePasswordDocument, ref WritePasswordTemplate, ref Format, ref Encoding, ref Visible); docWord.ActiveWindow.Selection.WholeStory(); docWord.ActiveWindow.Selection.Copy(); IDataObject data = Clipboard.GetDataObject(); _RichTextBox.Rtf = data.GetData(DataFormats.Rtf).ToString(); docWord.ActiveWindow.Close(ref saveChanges, ref routeDoc); appWord.Quit(ref saveChanges, ref originalFormat, ref routeDoc);




Reply With Quote