none
Open Word document from ASP.NET page in C# RRS feed

  • Question

  • Hi,<o:p></o:p>

    I am trying to open a Word document
    in an asp.net page in C#. The test code is like this:<o:p></o:p>

    using Microsoft.Office.Interop.Word;<o:p></o:p>

    protectedvoid btnTry_Click(object
    sender, EventArgs e)
    <o:p></o:p>

    {<o:p></o:p>

    Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();<o:p></o:p>

    object nullobj = System.Reflection.Missing.Value;<o:p></o:p>

    object file ="Test.doc";<o:p></o:p>

    Microsoft.Office.Interop.Word.Document doc = new
    Microsoft.Office.Interop.Word.Document();
    <o:p></o:p>

    doc = wordApp.Documents.Open(ref file, ref nullobj, ref nullobj, ref
    nullobj, ref nullobj, ref
    nullobj,
    <o:p></o:p>

    ref nullobj,ref nullobj, ref nullobj, ref
    nullobj, ref nullobj, ref
    nullobj);
    <o:p></o:p>

    string result = doc.Content.Text.Trim();<o:p></o:p>

    txtTest.Text = result;<o:p></o:p>

    }<o:p></o:p>

    But I got an error at<o:p></o:p>

    Microsoft.Office.Interop.Word.Document doc = new
    Microsoft.Office.Interop.Word.Document();
    <o:p></o:p>

    The error message is:<o:p></o:p>

    Retrieving the COM class factory for component
    with CLSID {00020906-0000-0000-C000-000000000046} failed due to the following
    error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005
    (CO_E_SERVER_EXEC_FAILURE)).
    <o:p></o:p>

    Is there any one can help me on this issue?<o:p></o:p>

    Thanks,<o:p></o:p>

    Yuhu Che<o:p></o:p>


    Monday, January 14, 2013 8:04 PM

Answers

  • automating office apps from inside IIS is not supported. Please consider using open xml sdk to achieve your goal (of course if this document is docx or similiar 2007 or newer format).
    Monday, January 14, 2013 8:56 PM

All replies

  • automating office apps from inside IIS is not supported. Please consider using open xml sdk to achieve your goal (of course if this document is docx or similiar 2007 or newer format).
    Monday, January 14, 2013 8:56 PM
  • Hello,

    you can use C# Word Reader by eleriumsoft.com to read text from .doc/.docx files. It is very fast and powerful component, but it is not free. Or you may look at this article:

    http://www.codeproject.com/Articles/3959/Microsoft-Word-Documents-from-ASP-NET

    Tuesday, March 12, 2013 4:31 AM