1

I'm currently trying this:

using DocumentFormat.OpenXml.Packaging;
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(fileNameDocx as string, true))
{
      var xdoc = wordDoc.MainDocumentPart;

      mainWebBrowser.NavigateToString(xdoc.Document.OuterXml.ToString());
} 

But this just gives me the text and none of the formatting. Is it possible to show a ".docx" in a webbrowser control like this?

Justin
  • 609
  • 2
  • 10
  • 21
  • Did you see this http://stackoverflow.com/questions/10681035/vsto-integration-in-asp-net-web-application and – Kiru Jun 08 '12 at 14:10

2 Answers2

2

There are some articles related to DOCX to HTML converition:

Please try these approaches above. Hope that helps

Community
  • 1
  • 1
Dmitry Pavlov
  • 30,789
  • 8
  • 97
  • 121
  • I'm marking this as the answer because I found this solution too. However I think I am going about my problem the wrong way by trying to use the OpenXML SDK. I have Word 2010 installed on the machine that will be doing this and there is not much difference between this solution and just saving as HTML. Thanks. – Justin Jun 12 '12 at 12:56
  • Saving as HTML requires to have MS Word installed on computer where your application is being executed. So in this case you will have a dependancy to MS Word. Transforming OpenXML to HTML - is more complex, but this code will be able to work on computer with no MS Word installed. – Dmitry Pavlov Jun 13 '12 at 08:32
  • Correct, I do have a dependency on Word. But since I know Word will be installed, this won't be a problem. – Justin Jun 14 '12 at 12:11
  • If you can get this to work and end up with clean HTML, you can then Convert the clean HTML to pdf using iTextSharp, thus creating a WordToPDF converter without using interop – Pierre Feb 01 '14 at 07:22
0

If you'd like to show XML in web browser control, you might need to:

  1. load this XML to XDocument,
  2. prepare HTML template with block,
  3. and then - write formatted XML from XDocument into PRE block.

You could either read the final HTML into string and use 'mainWebBrowser.NavigateToString' as you mentioned, or write HTML file to drive and read it from there into your mainWebBrowser

Hope that helps

Community
  • 1
  • 1
Dmitry Pavlov
  • 30,789
  • 8
  • 97
  • 121
  • I was actually hoping the document would display with the actual DOCX Word formatting, possibly using XSLT styles. That is not the case though. I also tried loading this into an XDocument. Also if any images are embedded into the document, for them to show also. – Justin Jun 08 '12 at 16:52