Not able to open word file from after deploy in web server(iis) RRS feed

  • Question

  • Hi,

    We are unable to add and download  word file. Same below code is working while i am running from visual studio, but this same code not working from IIS web server. This below Add document code failing when i am running from IIS, not able to add document  from path.

    document = application.Documents.Add(Template: path);

    Please check the below source code

    application.Documents.Add was causing issue, please check the below source code  
    application = new Microsoft.Office.Interop.Word.Application();
    document = new Microsoft.Office.Interop.Word.Document();
    string path = string.Format("{0}{1}{2}", System.Web.Configuration.WebConfigurationManager.AppSettings.Get("InputFilePath").ToString(), docname, ConfigurationManager.AppSettings["FileExtention"].ToString());
    document = application.Documents.Add(Template: path);
    application.Visible = true;
    document.SaveAs(FileName: string.Format("{0}{1}", System.Web.Configuration.WebConfigurationManager.AppSettings["OutputFilePath"].ToString(), unqnum));
     Response.ContentType = "application/octet-stream";
                        Response.AppendHeader("Content-Disposition", "attachment; filename=" + unqnum);

    Error:  Word was unable to read this document. It may be corrupt. Try one or more of the following: * Open and Repair the file. * Open the file with the Text Recovery converter.

    Thanks for you help


    Wednesday, February 20, 2019 6:58 AM

All replies

  • Hi AshisP,

    Thank you for posting here.

    Since your question is more related to IIS, you could post a new thread in IIS forum.

    The CLR Forum discuss and ask questions about .NET Framework Base Classes (BCL) such as Collections, I/O, Regigistry, Globalization, Reflection. Also discuss all the other Microsoft libraries that are built on or extend the .NET Framework, including Managed Extensibility Framework (MEF), Charting Controls, CardSpace, Windows Identity Foundation (WIF), Point of Sale (POS), Transactions. 

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Wednesday, February 20, 2019 8:25 AM