Free Support Forum - aspose.com

Cannot Read From a Saved Stream

Hi,
I’m using the evaluation copy right now, and I’ve created a document from a template which was in a memory stream (reading from the DB),

MemoryStream stream = new MemoryStream(docTemplate.Template);
Document doc = new Document((Stream)stream);

I’ve populated the doc with data and than I’ve saved it with save method to a new memory stream using;

MemoryStream mStream = new MemoryStream();
doc.Save(mStream, SaveFormat.Doc);

buffer = new byte[mStream.Length];
ReadStreamToBuffer(buffer, (Stream)mStream);

As soon as I saved it, I’ve tried to read mStream (saved doc) to a buffer but, read method of the stream returns 0 in the first try. So I cannot read the saved stream. Is this because I’m using the evaluation copy or can it be my mistake of usage? (maybe a bug?)

While debugging with calling the “doc.Save(mStream, SaveFormat.Doc);” method, I can see the saved stream can be filled by looking its size, but I cannot read from it.

Hi

Thanks for your inquiry. Please try using the following code snippet.

MemoryStream mStream = new MemoryStream();

doc.Save(mStream, SaveFormat.Doc);

byte[] buffer = mStream.GetBuffer();

Maybe this helps.

Best regards.

:slight_smile: Your answer inspired me to realize a mistake I was doing. As soon as I’ve set the offset position of saved stream to the beginning I’ve read it with no problem.
Thank you so much.