none
Saving and reading formatted text to database RRS feed

  • Question

  • Hi MS word gurus,

    I am working on a c# web application which processes Microsoft word documents uploaded thru the website.

    My objective is to loop through each bookmark and save the text (including the format) to a SQL server database. I need to read these text from the database and publish it to the web eventually. I am currently looking at 2 possible options:

    1. bm.Range.Formattedtext

    2. bm.Range.ExportFragment

    For option 1, what is the best way to insert the formatted text to the database?

    For option 2, I found several save options eg: wfFormatFilteredHTML. What is the recommended save option?

    What are the pros and cons between these 2 options and are there other possible solutions?

    Monday, December 17, 2012 4:01 PM

Answers

  • Hi Nagyer

    My recommendation would be for you to consider leveraging the Open XML file format, which your web application can access without needing to run the Word application. Word wasn't meant to be run as a "service" or in a network environment - it's targets end-users, only. The Open XML file format was designed for tasks such as this.

    To use it, you work with the standard Packaging and XML namespaces; there's also the Open XML SDK.

    I recommend you save the document content as Word Open XML, which can later be transformed to other formats (HTML, PDF) as required.


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, December 18, 2012 9:24 AM
    Moderator
  • Hi Nathan

    OpenXMLDeveloper.org is a good place to start.

    There are also a number of blogs on MSDN, from various people, dating back to when the file format was introduced (2006/2007) that give some background information. The Open XML SDK documentation is here:
      http://msdn.microsoft.com/en-us/library/bb448854.aspx

    There's also an Open XML SDK forum on MSDN:
      http://social.msdn.microsoft.com/forums/en-US/oxmlsdk/threads/


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, December 18, 2012 4:04 PM
    Moderator

All replies

  • Hi Nagyer

    My recommendation would be for you to consider leveraging the Open XML file format, which your web application can access without needing to run the Word application. Word wasn't meant to be run as a "service" or in a network environment - it's targets end-users, only. The Open XML file format was designed for tasks such as this.

    To use it, you work with the standard Packaging and XML namespaces; there's also the Open XML SDK.

    I recommend you save the document content as Word Open XML, which can later be transformed to other formats (HTML, PDF) as required.


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, December 18, 2012 9:24 AM
    Moderator
  • Thanks Cindy! Can you suggest any sites with examples and documentations?
    Tuesday, December 18, 2012 4:00 PM
  • Hi Nathan

    OpenXMLDeveloper.org is a good place to start.

    There are also a number of blogs on MSDN, from various people, dating back to when the file format was introduced (2006/2007) that give some background information. The Open XML SDK documentation is here:
      http://msdn.microsoft.com/en-us/library/bb448854.aspx

    There's also an Open XML SDK forum on MSDN:
      http://social.msdn.microsoft.com/forums/en-US/oxmlsdk/threads/


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, December 18, 2012 4:04 PM
    Moderator