When trying to read a MemoryStream I got the following error message:
Here is the code I was using:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var template=File.ReadAllBytes("template.docx"); | |
var templateStream=new MemoryStream(template); | |
//WmlDocument is part of OpenXML PowerTools | |
var wmlDoc = new WmlDocument(new OpenXmlPowerToolsDocument(filename, templateStream)); |
Couldn't be any simpler but unfortunately it didn't work.
I couldn't figure out what I did wrong...until I noticed the following in the documentation:
This constructor does not expose the underlying stream. GetBuffer throws UnauthorizedAccessException.
Aha, it seems that the OpenXmlPowerToolsDocument is calling GetBuffer behind the scenes. So we need to use a different constructor:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var template=File.ReadAllBytes("template.docx") | |
var templateStream = new MemoryStream(template,0, template.Length,writable:false, publiclyVisible:true); | |
//WmlDocument is part of OpenXML PowerTools | |
var wmlDoc = new WmlDocument(new OpenXmlPowerToolsDocument(filename, templateStream)); |