0

I am converting and saving a word document to SQL Server database as varbinary. I can save the data. I want to display the uploaded Word document back to the user just like how a resume looks in Word, as if the actual Word document was embedded in the web page itself.

I have the below code, which is downloading the saved Word document as a Word file. Please tell me which is the best control to display the word document also inside the browser.

 byte[] fileContent = new byte[fuResume.PostedFile.ContentLength];
            fuResume.PostedFile.InputStream.Read(fileContent, 0, fuResume.PostedFile.ContentLength);
            //lblAppliedMessage.Text = ByteArrayToString(fileContent);

            //lblAppliedMessage.Text = BitConverter.ToString(fileContent).Replace("-", string.Empty);


            byte[] btYourDoc;
            btYourDoc = fileContent;
            Response.ContentType = "application/ms-word";
            Response.AddHeader("Content-Disposition",
            "inline;filename=yourfilename.doc");


            Response.BinaryWrite(btYourDoc);
            Response.End();
Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Tan
  • 778
  • 3
  • 18
  • 36

1 Answers1

0

Provided that you have word on the web server or on the application server, I would save to a temp file the stream coming from the database, open it with word, save as html and render this html in the web browser.

Edit:

as mentioned in the link provided in the comment: http://support.microsoft.com/default.aspx?scid=kb;EN-US;257757 you should possibly avoid usage of Word/Excel Automation on server side code, here an extract from this article from MS:

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

Suggested solutions/alternatives are:

Word Automation Services Overview

Excel Services Overview

Davide Piras
  • 43,984
  • 10
  • 98
  • 147
  • Microsoft specifically says you shouldn't install Microsoft Office on a server as it has issues with memory leaks when run over a long period of time. – rtpHarry Nov 28 '11 at 19:22
  • @rtpHarry can you please send a link of this statement from Microsoft? If you dispose and release office objects after usage I think either this is not the cause of leaks are minimal anyway. I have never seen the article you are mentioning (but not linking yet), in any case isn't the memory released once word is closed or IIS app pool recycled? – Davide Piras Nov 28 '11 at 19:50
  • 1
    sure, the link is here http://support.microsoft.com/default.aspx?scid=kb;EN-US;257757 – rtpHarry Nov 28 '11 at 20:50