views:

103

answers:

2

I am attempting to write an add-in for Microsoft Word 2007. I'd like to create a Ribbon Button that when clicked, gets a FileStream for the current or active document. I would assume that is possible with the Visual Studio Tools for Office. Does anyone have any sample code that would show how to do this?

Let me know if you have any questions. Thanks

A: 

Try this out on the ribbon button code (for document-level add-ins):

string document = Globals.ThisDocument.Application.ActiveDocument.FullName;

Then use the standard example for FileStream.Read on MSDN

*Might need to prompt or force a save first, if unsaved changes exist.

Mike Regan
A: 

Another approach might be to get the XML representation of the open document, using .WordOpenXML

That will be the current state (ie including unsaved changes).

plutext
That would be awesome! I wonder if the OpenXML SDK could carry the XML string over to the .docx container.
Mike Regan
If you mean you want to take the XML string, and um, 'unmarshal' (sorry, Java terminology) it to OpenXML SDK objects, manipulate those, and then convert back to an XML string for re-insertion back into the live Word document, then yes, that's do-able.
plutext