none
Questions about Interop assemblies and compatibility with multiple versions of word RRS feed

  • Question

  • I am working on an application that manages large projects.  It is basically an author's tool to manage novels they are working on.  One of the big things that is vital to the application is the ability to be fluid about order of your written segments without the user having to worry about dealing with the word files. 

    So I have been making good progress with something that uses the word interop dlls to assemble a chapter from the collection of sections that are in that chapter for example.  My application basically needs to be able to refresh running word counts, assemble chapters and novels from the collections of files, and handle imports of a chapter or novel and update the appropriate section word files.

    I have all of that either working or well under way.  However, I am coming across a big concern.  I just upgraded to office 2010 from 2007 when I did a format and clean install on my dev environment.  I realized when I got my development up and running for my novel writing application that I would have to reference a different set of dlls now that I am on 2010.

    My end goal is to have a product that I can release to end users who could be using pretty much any version of office since 2005 (I think that's when they started on the docx instead of doc format).  I would also like my application to work without requiring them to update or change my application if they were to upgrade word. 

    I know that I can't guarantee that will work against something in the future like a release of Office 2012 or something.  However, I would like my application to work nicely for someone with 2007, and to continue working when that user upgrades to 2010.

    So are the interop assemblies even the right tool for that?  Obviously the interop assemblies won't work for someone who is using open office, but I am wondering if I should look for something that will work with the word doc files without needing to depend on a specific version of office to do their thing.

    Thanks for reading, and I will really appreciate any information or answers people can provide.


    All that is gold does not glitter, Not all those who wander are lost
    • Edited by DannyStaten Thursday, December 30, 2010 4:18 AM because I can't preview my post and I had a few typos
    Thursday, December 30, 2010 4:17 AM

Answers

  • Hi Danny

    If you're running Word in the background and are generating Word documents (or manipulating *.docx/*.docm files) I recommend you look into using the Office Open XML file format and the Open XML SDK. Then you won't need to automate ("interop") with the Word application at all. It won't need to run in the background. No worries which version of Word...

    Embedding the relevant parts of the Office object model: When you've set a reference to the object library, look in the Properties pane. Set "Embed Interop Types " to True if it isn't already.

    See also the last section of this article:
    http://msdn.microsoft.com/en-us/magazine/ff796223.aspx


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by DannyStaten Friday, December 31, 2010 3:11 AM
    Thursday, December 30, 2010 4:01 PM
    Moderator

All replies

  • Hi Danny

    You don't specify, but I'm assuming this is a Visual Studio / .NET Framework solution?

    Are you interacting with the user in the Word UI, or is the user interaction all through a Windows Form (or similar) and you're manipulating the Word documents "in the background"?

    Assuming you require the Word UI when interacting with the user:

    1. The rule is that you must compile your code against the oldest version of the Office application you want to support. The Office 2007 and 2010 PIAs will automatically re-route calls to the PIAs of earlier versions to themselves. The same does NOT hold for the reverse situation, however.
    2. If you're targeting the .NET Framework 4.0 you have the option of embedding the parts of the object model you're using IN your solution. This makes it PIA (and version) independent.
    3. For earlier versions of .NET the only way to have a solution be PIA and version independent is to use late-binding (for C# that means GetType().InvokeMember())

    Cindy Meister, VSTO/Word MVP
    Thursday, December 30, 2010 7:08 AM
    Moderator
  • Thank you for the good information.  I am using .Net 4.0 and my application is a WPF application.  I am running the word operations in the background. 

    Do you know where I can find more information about the second point you mention about embedding parts of the object model in my solution?  That sounds like it could be very handy.

    thanks,

    Danny


    All that is gold does not glitter, Not all those who wander are lost
    Thursday, December 30, 2010 3:05 PM
  • Hi Danny

    If you're running Word in the background and are generating Word documents (or manipulating *.docx/*.docm files) I recommend you look into using the Office Open XML file format and the Open XML SDK. Then you won't need to automate ("interop") with the Word application at all. It won't need to run in the background. No worries which version of Word...

    Embedding the relevant parts of the Office object model: When you've set a reference to the object library, look in the Properties pane. Set "Embed Interop Types " to True if it isn't already.

    See also the last section of this article:
    http://msdn.microsoft.com/en-us/magazine/ff796223.aspx


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by DannyStaten Friday, December 31, 2010 3:11 AM
    Thursday, December 30, 2010 4:01 PM
    Moderator
  • Sweet the open xml is exactly what I was looking for.  Thank you very much for taking the time to answer my questions.
    All that is gold does not glitter, Not all those who wander are lost
    Friday, December 31, 2010 3:12 AM