c# error copy word document to textbox

0

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);
c#
asp.net
exception
ms-word
asked on Stack Overflow Aug 16, 2012 by user1557308 • edited Aug 16, 2012 by user1557308

1 Answer

0

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.

answered on Stack Overflow Aug 16, 2012 by stuartd • edited Aug 16, 2012 by stuartd

User contributions licensed under CC BY-SA 3.0