I want to copy a Word document into a textbox in c# web application. I added the Microsoft Word 10.0 Object Library. But I am getting an exception.
ERROR: The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
Microsoft.Office.Interop.Word.ApplicationClass wordApp = new ApplicationClass();
object file = filePath;
object nullobj = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(
ref file, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
TextBox1.Text = doc.Content.Text;
doc.Close(ref nullobj, ref nullobj, ref nullobj);
wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
You should use Microsoft.Office.Interop.Word.Application
instead of ApplicationClass
` (which is documented as 'Reserved for internal use'): see http://blogs.msdn.com/b/ptorr/archive/2004/02/05/67872.aspx for details of why.
User contributions licensed under CC BY-SA 3.0