Im having trouble appending the data in a MemoryStream to other Memorystream allready created an full of data. I'm doing this to create an excel from two different sources.
First I create the father memorystream:
MemoryStream obj_stream = new MemoryStream(100000000);
var tempFile = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid() + ".xls");
obj_stream.Write(File.ReadAllBytes(tempFile), 0, File.ReadAllBytes(tempFile).Length);
File.Delete(tempFile);
Then I create the son memorystream from a compositeLink.ExportToXls
compositeLink.CreatePageForEachLink();
compositeLink.PrintingSystemBase.XlSheetCreated += PrintingSystemBase_XlSheetCreated;
using (MemoryStream stream = new MemoryStream(100000000))
{
compositeLink.ExportToXls(stream, new XlsExportOptions() { ExportMode = XlsExportMode.SingleFilePageByPage });
obj_stream.Write(stream.ToArray(), 0, stream.ToArray().Length);
}
Finally I write the stream to a Page.Response
if (Page == null || Page.Response == null)
return;
string disposition = saveAsFile ? "attachment" : "inline";
Page.Response.Clear();
Page.Response.Buffer = false;
Page.Response.AppendHeader("Content-Type", string.Format("application/{0}", fileFormat));
Page.Response.AppendHeader("Content-Transfer-Encoding", "binary");
Page.Response.AppendHeader("Content-Disposition", string.Format("{0}; filename={1}.{2}", disposition, fileName, fileFormat));
Page.Response.BinaryWrite(obj_stream.ToArray());
Page.Response.End();
What is happening I believe is that either one or the other gets overwritten by the other, depending on which one I do the "nameOfTheStream".write()