Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to write a packaging.package to a stream without having to save it to a file first?
    primarykey
    data
    text
    <p>I have a System.IO.Packaging.Package in memory (it is a WordprocessingDocument) and want to stream it down to browser to save it. The word document has been modified by the MVC-based application and the resulting file has been modified for the current request.</p> <p>I understand the package represents a 'zip' file containing a number of parts. These parts include headers, footers and main body document. I've modified each individually and now want to stream the package back to the user.</p> <p>I can get the individual part streams... package.GetPart(new Uri("/word/document.xml", UriKind.Relative)).GetStream()</p> <p>However I'm missing how to get an output stream on the entire document (package)- without writing to the file system.</p> <p>Thanks in advance</p> <p>No- what I think I need is something like this... I've already read in the template document and made modifications in memory. Now I want to stream a modified document (leaving the template un-touched) back to the user.</p> <pre><code> MemoryStream stream = new MemoryStream(); WordprocessingDocument docOut = WordprocessingDocument.Create( stream, WordprocessingDocumentType.Document); foreach (var part in package.GetParts()) { using (StreamReader streamReader = new StreamReader(part.GetStream())) { PackagePart newPart = docOut.Package.CreatePart( part.Uri, part.ContentType ); using (StreamWriter streamWriter = new StreamWriter(newPart.GetStream(FileMode.Create))) { streamWriter.Write(streamReader.ReadToEnd()); } } } </code></pre> <p>Unfortunately- this produces a 'corrupt' word document... </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload