Working with Docx using Silverlight and WPF - XBAP

by Bobbi Perreault 4. January 2009 04:34
Share on Facebooksmiley-sm

In exploring the possibility of using Silverlight to write an editor for Word documents, I learned a few things that may or may not be obvious to my smarter programming friends out there.

In any case, for what it's worth, here are some links, advice, and lessons learned from a weekend of knocking my head against the wall.

To begin with, the problem statement (as stated to me by my client): "We need to be able to edit a Word document (Office 2007 to be exact), track any changes made to the document, and display the document back to the user with the changes modified.  And we want to do this with Silverlight."

I started by searching the web for contributions by others.  I found quite a lot of great information to get me started.  My initial conclusion was that Silverlight, while a wonderful tool, was not the BEST tool for this job.  Further conversations with the client assured me that the only platform requiring support was Windows.  This said XBAP would be a better place to start since WPF has FlowDocument.

NOTE:  XBAP OpenFlowDocumentExtensions - will not work with an XBAP application because it requires full trust.  So just don't even try them together.  Unfortunately, this makes the job immensely more difficult.  Same goes for multi-window XBAP.

My Getting Started Links.

  (Don't worry, if you're short on TIME, skip to the end, where my conclusions and sample code are) 

Whether you decide to go with WPF or a combination of Html and Silverlight, I found examples of how to parse DOCX / OpenXML using XSLT, how to parse using LINQ, and also links to Microsoft’s SDK for working with DOCX / OpenXML . There is much information available.

DOWNLOAD http://www.microsoft.com/downloads/details.aspx?FamilyID=ad0b72fb-4a1d-4c52-bdb5-7dd7e816d046&DisplayLang=en:  THIS IS OPENXML TECHNOLOGY PREVIEW, read and write openxml documents.

this blog entry has example code to import word xml into wpf.:  http://blogs.microsoft.co.il/blogs/tamir/archive/2008/04/22/wordml-to-flowdocument-how-to-convert-docx-files-to-wpf-flowdocument.aspx

this blog entry has example code to import word xml into html page.  uses IHttpHandler too.:  http://blog.maartenballiauw.be/post/2008/01/Preview-Word-files-(docx)-in-HTML-using-ASPNET-OpenXML-and-LINQ-to-XML.aspx

Rendering WordML documents in ASP.NET:  Posted by: Signs on the Sand, on 01 May 2006 | View original

eXml

http://www.codeproject.com/KB/WPF/OpenFlowDoc.aspx:  Parsing an OpenXML Document using XLINQ

http://www.emxsoftware.com/LINQ/ParsingWordMLusingXLinq:  More on parsing OpenXML with XLINQ

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/2b7720c2-0a14-43f0-8931-d91ef87d0cda/:  Advice on parsing XML for WPF

http://openxmldeveloper.org/articles/OpenXMLDocFromDotNetWebVersion.aspx: Create WordXML without Word

TextGlow - too bad this wasn't working for me when I visited. 

http://www.openxml.biz/OpenXMLWriter.html:  OpenXMLWriter

http://conceptdev.blogspot.com/2007/03/open-docx-using-c-to-extract-text-for.html : CSharp to extract WordML

http://www.codeproject.com/KB/office/ExtractTextFromDOCXs.aspx: DOCX to Text

http://blogs.msdn.com/karstenj/archive/2007/01/11/the-definitive-post-on-xbap-trust-levels.aspx: The Definitive Post on XBAP trust levels.

http://blogs.msdn.com/akshayns/archive/2007/05/02/clickonce-deployment.aspx: ClickOnce deployment and Trust

http://dedjo.blogspot.com/2008/04/wordml-to-flowdocument-how-to-convert.html:WordML to Flow Document.

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c2f23026-1e7a-4efa-8bab-2479f404634d/: Images in FlowDocument

http://www.charlespetzold.com/blog/2006/01/180334.html: Tables in RichText

Conclusions:

Up front:  Tables are not supported in any of the online examples we encountered.  If your documents for WPF or silverlight contain tables then you have a LOT of work to do to complete that piece.  I found this part extremely complicated and time consuming to implement and so in other words, it didn't get done.

The final project used OpenFlowDocumentExtensions which is a project I used to display the docx file. And I used it to feed the docx file to the Writer class

And there's some work done in the linked project for comparing original Docx to Modified Docx.

Here's a link to the DocxEditor project I was working on, when I gave up because tables are so darn hard.  Maybe it'll help someone out there - It's basically a lot of pieces of other people's work, but I spent four days to get to this point so I hope it helps someone.

 

Tags: , ,

How To

 

RSS Feed FriendFeed