Wednesday, January 6, 2010

How to produce a docx file on WCF service

That was my problem exactly until I found this post that solved my problem.

Solution is very simple:

  • Get the context to the service (If you need a user input). Open template (in example it is copied to a file with random name and then open). Browse the xml for appropriate tag(s) and change the content. Return the stream to the client and save it as a file.
  • It would be nice to have more generic solution but this is simple and clean. Only problem is that modifications of code cannot be avoided if template changes, but on the other hand templates can be very complex. In that case take a look at the docx or flexdoc