How to save MS Word doc to database and show on webpage??
I have a requirement to upload a MS Word document to database and need to show on Webpage. Word document may also have images. Does anybody help me out in that kind of scenario? Thanks in advance.


Ankur JainRank #2,475 · 567 reputationPosted Aug 5, 2014, 3:51 AM EDT
Rishikesh Kumar SinghRank #1,250 · 1.4K reputationPosted Aug 6, 2014, 2:28 AM EDT
After retrieving that saved byte from database i want to show on webpage itself (inside a div as innerhtml). I want to show the contents as it was (with images and formating). So, kindly help me in this scenario.
Ankur JainRank #2,475 · 567 reputationPosted Aug 6, 2014, 3:25 AM EDT
checkout the thread, may be it will help you...
http://aspsnippets.com/Articles/Display-Word-document-on-web-page-in-ASP.Net.aspx
Kyle Story24 reputationPosted Nov 28, 2014, 12:42 AM EST
Well you will definitely need to convert your DOCX to a HTML format with C# in order to add that content to a DIV. But using the word interop with C# on server side does have its issues, also you cannot avoid the steps of generating the physical files which you would eventually need to delete.
But the problem that I had with this approach is that you simply cannot (at least I didn't find any way...) embed the images as data URIs:
http://en.wikipedia.org/wiki/Data_URI_scheme
So as an alternative here is an approach that you can use to read and convert your DOCX file's stream in C# (no physical file is needed) and then retrieve the HTML content as a string with an embedded images inside of it:
// Load DOCX documment's content from a stream. var document = DocumentModel.Load(docxStream, LoadOptions.DocxDefault); string htmlContent; using (Stream htmlStream = new MemoryStream()) { // Set HTML format options. var options = new HtmlSaveOptions(); options.EmbedImages = true; options.HtmlType = HtmlType.HtmlInline; // Save documment's content in HTML format to stream. document.Save(htmlStream, options); htmlStream.Seek(0, SeekOrigin.Begin); // Get HTML content as string. htmlContent = new StreamReader(htmlStream, options.Encoding).ReadToEnd(); }The code uses this word component for .NET framework.