Welcome to OpenXML Developer
Sign in
|
Join
|
Help
Search
OpenXML Developer
»
Development Tools
»
.Net
»
Re: Failure to create package of opened .docx
Failure to create package of opened .docx
Last post 07-28-2008, 12:12 AM by
Sheela E N
. 2 replies.
Sort Posts:
Oldest to newest
Newest to oldest
Previous
Next
07-17-2008, 12:13 PM
3478
deeflex
Joined on 07-17-2008
Posts 2
Failure to create package of opened .docx
Reply
Quote
Hi
I'm developing a Word add-in and I'm trying to access the xml-files of the .docx file which is currently opened.
Here's the essential parts of my code:
private Word.Document doc;
...
String path = doc.FullName;
String documentPathInPackage = "word\\document.xml";
Uri partUri = Packaging.PackUriHelper.CreatePartUri(new Uri(documentPathInPackage, UriKind.Relative));
Packaging.Package docPackage = Packaging.Package.Open(path, FileMode.Open, FileAccess.ReadWrite);
It's the last line that fails, the debugger says "The file is currently being used by another process", which is true.
So my question is how can I do this in a neat way? Is it possible to unlock the file from the process using it?
Thanks in advance.
Report abuse
07-23-2008, 5:46 AM
3500
in reply to
3478
deeflex
Joined on 07-17-2008
Posts 2
Re: Failure to create package of opened .docx
Reply
Quote
Hi all!
Just wanted to say that I solved the problem by opening the file in read-only mode, which is not a perfect solution.
Correct line is:
Packaging.Package docPackage = Packaging.Package.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
Report abuse
07-28-2008, 12:12 AM
3505
in reply to
3500
Sheela E N
Joined on 07-11-2007
Posts 361
Re: Failure to create package of opened .docx
Reply
Quote
Hi,
First you open the package as
pack =
Package
.Open(
@"file path"
,
FileMode
.Open,
FileAccess
.ReadWrite);
Then create the main document part as
PackagePart
mainPart = pack.CreatePart(uriHeaderFooter,
"content type"
);
Sheela
Report abuse
Terms of Use
|
Code of Conduct
|
Privacy Statement
|
Contact Us
© 2006 Microsoft Corporation. All rights reserved.