none
C# (2010) How do you get a Word Doc Template to be programable by C# RRS feed

  • Question

  • Hi All,

    I am having a issue with a  MS-Word Template(2010) where I have set up field names and tags in the template and then restricted the template. I need to access these fields so that I can store them to a SQl Database.

    Issues I have are : Word document keeps opening up a Word Document interface. Will not stay nor display in a Web Browser Interface (webbrowser1 or axWebBrowser1). And Finally I can't gain access to the field names example word template field name trcknum.

    Using C# 2010 so please due not give fixes for 2008 or 2005 version as Word has new rules in effect for 2010.

    Thanks in advance :)

     

    • Moved by Neddy Ren Thursday, September 1, 2011 3:46 AM (From:Windows Forms Sample Applications)
    • Changed type Cindy Meister MVPModerator Thursday, September 1, 2011 1:08 PM it's a question
    Wednesday, August 31, 2011 4:16 PM

All replies

  • Hi "CW"

    We need more information. Your problem description is too vague to understand exactly what the situation is.

    1. May we assume the documents created from this template are in the *.docx file format?

    2. Exactly what functionality was used in the template to "set up field names and tags"?

    3. Exactly what functionality ws used to "restrict the template"?

    Do you expect to be able to manipulate the document ("access the field names") while it's opened in a web browser or are the two questions unrelated?

    What is it you need to do when you "access the field names", exactly?


    Cindy Meister, VSTO/Word MVP
    Thursday, September 1, 2011 1:12 PM
    Moderator
  • <<Yes the Word Document was created in the Word 2010 Enviroment and has a *.docx format. The field names and tags were set by using the developer ribbon as well as the edit restricting set to fields only in the Office Word 2010.>>

    I'm afraid this is still not specific enough. Word has four different kinds of "fields" and four different kinds of protection. You need to be very specific in order for us to give you a meaningful reply.

    FWIW, though, your best bet would probably be to use the standard Packaging and XML namespaces or the Open XML SDK to extract the information from the closed document file. That way you don't need to have Word available or running on the machine/server that's supposed to extract the data and put it in the database.

    You'll find more information about Open XML at OpenXMLDeveloper.org.

    And the best "type" of field to use would probably be Content Controls.

    <<I have also seen that 2010 Net Studio has a C# / Office 2010/ Word Document right in the Create new project>>

    This would be VSTO and probably not appropriate for a document you're sending around be email.


    Cindy Meister, VSTO/Word MVP
    Thursday, September 1, 2011 4:39 PM
    Moderator
  • Another department takes the word doc and imports it to my program were I want the program to take the values that the customer entered in on the Word Document and transfer this info to a SQL server for storage. The SQL transfer I understand, the issue is how do you access the word document field names / tags so i can transfer values out to SQL and also write the SQL stored values back to the word document ?

    Hi CW-IT Programmer,

    Below links are about how to load SQL Server data into Word and how to convert Word Table to SQL table. Please check, hope they could be helpful.

    http://www.simple-talk.com/sql/t-sql-programming/writing-to-word-from-sql-server/
    (Writing to Word from SQL Server)

    http://msdn.microsoft.com/en-us/library/aa192487(v=office.11).aspx
    (Walkthrough: Building a Word Document Using SQL Server Data)

    http://msdn.microsoft.com/en-us/library/aa192485(v=office.11).aspx
    (Walkthrough: Loading SQL Server Data into a Word Table)

    http://wordtosql.codeplex.com/ (Convert Ms Word Table to Sql Table)

    If I misunderstood, please feel free to follow up.

    Have a nice day.

    Best regards


    Liliane Teng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, September 7, 2011 6:36 AM
  • HI CW

    If you'd work with me I'm sure we'd arrive at a solution. But you do have to provide the requested information...


    Cindy Meister, VSTO/Word MVP
    Wednesday, September 7, 2011 1:48 PM
    Moderator
  • Hi CW IT

    OK, this makes this a VSTO document, so the best place to discuss it would probably be / have been the VSTO forum. But for the moment - thank you for specifying that you're using plain text controls :-)

    Going back to your original message:

    1) You cannot use a VSTO document in a web browser interface. It must be opened in the Word application window

    If you need this, then you cannot use a VSTO document. As far as I can tell, you don't need VSTO, necessarily. It could make certain things simpler in your scenario, but if the web browser is a requirement, then that's a no-go.

    Next question from my side, in order to narrow down the possibilities of what follows: When you exchange data between the document and SQL Server, will this be while you're interacting with the user? Or would it be something you'd prefer to do "server-side" (when the user is done with the document)?


    Cindy Meister, VSTO/Word MVP
    Wednesday, September 7, 2011 4:16 PM
    Moderator
  • here is the .Net Application.

    This is the best I can explain it and visualize it. This is where I am at and want to procede in .Net C# application. hope this clarifises the situation and has answered all questions.

    the word document does not have to be view can be hidden in the C# application just that the information will be imported to the returnauth8DForm.cs this connects to the SQl Server and is were I wish to connect to the ReturnAuthWordDocument.This.Document.cs



    Hi CW-IT Programmer,

    I could reproduce the information your described. But I am sorry I could not understand what is your current concern now? Could you please describe the issue more specific? Do you get any errors or exceptions about this C# application? Or do you get any unexpected effects when you convert Word to SQL database or load SQL database data into Word?

    By the way, as Cindy suggested, you could also consider to post this issue on VSTO forum for more suggestions.

    http://social.msdn.microsoft.com/Forums/en/vsto/threads

    Have a nice day.

    Best regards


    Liliane Teng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 8, 2011 8:40 AM
  • Hi CW

    OK... On the surface, the VSTO solution is good, but there's a "gotcha": in order for this to function at every step of the way, the person using the solution must have access to the VSTO code-behind. The code used for the database stuff is not going to travel with the document from you, to the customer, then to the vendor.

    Also, if the customer does not have the code-behind, he's going to get warnings. This can be avoided, but the vendor will definitely have to have the code-behind.

    Have you allowed for these factors in your scenario?

    If you have, then VSTO is a good way to go and you should be able to achieve your goal using data caching, discussed here:
    http://msdn.microsoft.com/en-us/library/xst4e83b.aspx
    And getting at that data at a later point:
    http://msdn.microsoft.com/en-us/library/xst4e83b.aspx

     


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Liliane Teng Monday, September 12, 2011 2:52 AM
    • Unmarked as answer by CW-IT Programmer Monday, September 12, 2011 12:39 PM
    Thursday, September 8, 2011 8:48 AM
    Moderator
  • Hi CW

    Did you investigate the information in those links I gave you?

    I do this support in my "free time". I'm in the middle of a huge project right now myself and don't have time to work up an example for you. Like you, I get paid for doing that kind of work...

    The other approach, that you turned down categorically because you feel you can't learn to work with XML, would be to extract the data from the non-VSTO document's Open XML file format. In the long run, that would be the simplest way to go.

    Or the software on the vendor side would have to automate the Word application (open the document, process it). But in that case you should not be attaching a vSTO solution to it.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Liliane Teng Monday, September 12, 2011 2:53 AM
    • Unmarked as answer by CW-IT Programmer Monday, September 12, 2011 12:35 PM
    Friday, September 9, 2011 10:01 AM
    Moderator
  • Hi Cindy,

    I fully understand. I reviewed the links above they both point to the same site with description info and other links.

    Thank you

    CW


    I Have given up on this question I found the results and it had nothing to do with word at all but C# so please stop changing the answer to a VSTO by a moderator. Thanks Again but sorry that is not the answer!!!!!!!
    Friday, September 9, 2011 12:09 PM
  • 100 ways to skin a cat and 2 million ways to program it !!!!!!

    Monday, September 12, 2011 12:38 PM