We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Trying to generate multiple documents and send to client immediately

I have a .NET web application that generates several documents using Aspose.words. I need to send all of the generated documents to the client machine as soon as they are generated. As I can’t use ‘doc.Save(Response, “document1.docx”, ContentDisposition.Inline, Nothing)’ due that that only sending the last file referenced I think my best shot is to bundle the generated documents into a .zip archive and send that to the client machine. What I’m attempting right now is to save the documents to a stream and save the stream to the zip archive using Ionic Zip. The issue I’m running into is that the files generated are empty and I’m not sure where I’m going wrong here. Any help/suggestions would be greatly appreciated. Code snippet is below:


Dim CLdoc As New Document(“C:/Temp/Cover Letter.docx”)
Dim CLbuilder As New DocumentBuilder(CLdoc)

'Build CLDoc content

Dim MTdoc As New Document(“C:/Temp/Master Terms.docx”)
Dim MTbuilder As New DocumentBuilder(MTdoc)

'Build MTDoc content
Dim CLDocStream As New MemoryStream
Dim MTDocStream As New MemoryStream

Using zip1

As New ZipFile()
zip1</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">AddEntry</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">(</span><span class="str" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: rgb(128, 0, 0);">"CL.docx"</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">,</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> CLDocStream</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">)</span></code></pre><pre class="lang-vb prettyprint prettyprinted" style="margin-top: 0px; margin-bottom: 10px; padding: 5px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; overflow: auto; width: auto; max-height: 600px; word-wrap: normal; color: rgb(0, 0, 0);"><code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit;"><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"><pre class="lang-vb prettyprint prettyprinted" style="margin-top: 0px; margin-bottom: 10px; padding: 5px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; overflow: auto; width: auto; max-height: 600px; word-wrap: normal;"><code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit;"><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">   zip1</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">AddEntry</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">(</span><span class="str" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: rgb(128, 0, 0);">"MT.docx"</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">,</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;"> MTDocStream</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">)</span></code></pre>
zip1</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">Save</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">(</span><span class="str" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent; color: rgb(128, 0, 0);">"c:/Temp/test.zip"</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">)</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; background-color: transparent;">

End Using

Hi Stephen,

Thanks for your inquiry. To check that Aspose.Words is saving document correctly, you can save your documents to disk and zip these document. Send the zip file to
client browser and delete the generated document.

Please make sure that you are saving the Word document to stream correctly. If you are using single MemoryStream object to save each document, please rewind the stream position back to zero (MemoryStream.Position = 0) so it is ready for next
reader.


...

docStream.Position = 0


Thanks Tahir. I realized that I needed to reset the memory stream position to the start of the stream after I had posted my question. I used a different method to reset the stream position:


CLDocStream.Seek(0, SeekOrigin.Begin)

Hi Stephen,

Thanks for your feedback. Yes, this should resolve your issue. Please let us know if you still face any issue and have any more queries.