none
Visual Studio 2010 & VSTO RRS feed

  • Question

  • VS2010 using C#, Word 2010

    1 solution, 2 projects. Main project is a WinForm with a button and a RichTextBox. When I click on the button, I want to open Word in VSTO which is the 2nd project and otherwise control the form. Mainly by copying the data from the RTB to the VSTO document. Edit the data and copy back to the RTB when done when closing the VSTO document.

    I'm at a loss on how to even open the VSTO document. I think once that is done, I'll be OK. Can this even be done?

    Cliff
    Tuesday, October 30, 2012 1:31 PM

Answers

  • you don't. You just start host application - here Word and instruct it to open document that hosts your vsto document-level customization. This is how you start vsto app.
    • Marked as answer by CW1255 Wednesday, October 31, 2012 5:50 PM
    Wednesday, October 31, 2012 2:07 PM

All replies

  • what do you mean by opening vsto document? you mean document with attached document-level customization? I guess normal word api should be sufficient, something along the lines of:

    var word = new Application();

    word.Documents.Open(path to file);

    Tuesday, October 30, 2012 2:12 PM
  • A VSTO project comes with it's own document/form. Word in this case. It isn't a file. I don't need a file, but I do need to monitor when the document is closed so I can copy the contents back to my RTB.

    • Edited by CW1255 Tuesday, October 30, 2012 2:20 PM
    Tuesday, October 30, 2012 2:18 PM
  • if you want to monitor when document is closed in word, or whole word process shuts down, then you can attach to proper event on word API in former case and user Process.Start and WaitForExit on returned object in latter case.
    Tuesday, October 30, 2012 9:08 PM
  • But I can't even start the process.
    Wednesday, October 31, 2012 12:40 PM
  • why you cannot start process? i think i do not understand your issue. Here is what i understood so far: you have to projects - one normal winforms app and second a vsto based deocument level customization for word. And from winforms app you want to start word with your document so your customization is loaded. Did i get this right?
    Wednesday, October 31, 2012 1:55 PM
  • You have that correct. I can't figure out how to start the VSTO app from the winform app.
    Wednesday, October 31, 2012 2:00 PM
  • you don't. You just start host application - here Word and instruct it to open document that hosts your vsto document-level customization. This is how you start vsto app.
    • Marked as answer by CW1255 Wednesday, October 31, 2012 5:50 PM
    Wednesday, October 31, 2012 2:07 PM
  • Oh, OK. Now it's making a bit more sense. I was thinking of it as a Parent-Owner/Child form. I still need to work it that way so that while the VSTO doc is open, the 'Parent'/Calling App is locked out from use.
    Wednesday, October 31, 2012 2:23 PM
  • if you want to maintain strict parent/child relation betoween your windows, simplest thing would be to move your winforms app also to VSTO and open it from there, this way simple ShowDialog will work the way you expect.
    Wednesday, October 31, 2012 2:42 PM
  • That would work if I were staying with a simple project. But this is part of a larger project. What I've described here is an attempt at proof of concept. I marked your reply above as the answer I needed.

    I'll post more details once it's all figured out.

    Thanks.

    Wednesday, October 31, 2012 5:51 PM