Word Addin fails in trying to access OpenXML functions

M

Michael Taube

Hello

I'm writing a COM based Word Add-in using VSTO 2005 SE. While the user is
interacting with my add-in, I would like to save custom information to the
currently active document file using the new System.IO.Packaging functions
(OpenXML). Conversely, I would like to read my own various packages from
within my add-in while the file is loaded.

However, Word seems to have the file opened in exclusive mode, so I can't
modify the file itself, nor can I open it just for reading. Does VSTO allow
me to access the underlying file so that it can remain compatible with the
new OpenXML API? If not, am I missing something obvious?

Thanks!

Mike
 
M

Michael Taube

OK I figured out half of it.. Using FileShare.Read, I was able to open the
currently opened file for reading in my packages.

But how do I open it for writing? Do I have to wait until the document is
closed down? If so, is that do-able from a COM/VSTO point of view?
 
M

Michael Taube

Well, I thought I had figured out half of it. It turns out my file was opened
by Word in read-only mode, so my addin was able to access the word file in
shared read.

As soon as I turned off the OS-level read only flag, my addin wasn't able to
access the data using the OpenXML API.

So I guess my original problem still stands -- how do I access the parts
within the package stored in the currently open document?

Thanks
 
M

Michael Taube

Thanks to Richard (MSFT) for suggesting a solution.

He suggests that a temporary copy of the document should be created and
using the OpenXML functions on the copy to access the data.

This works perfectly. I guess this leads to 2 questions:

1) Is this the recommended way of accessing parts within the currently open
package in Word?

2) How do I add to the package, since Word has a lock on the file while it's
open?

Thanks

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top