Following code block can be used to show user on Open/Save/Cancel dialogue box in browser for a memory stream.
if (ms != null)
{
Byte[] byteArray = ms.ToArray();
ms.Flush();
ms.Close();
Response.BufferOutput = true;
// Clear all content output from the buffer stream
Response.Clear();
//to fix the “file not found” error when opening excel file
//See http://www.aspose.com/Community/forums/ShowThread.aspx?PostID=61444
Response.ClearHeaders();
// Add a HTTP header to the output stream that specifies the default filename
// for the browser’s download dialog
string timeStamp = Convert.ToString(DateTime.Now.ToString(“MMddyyyy_HHmmss”));
Response.AddHeader(“Content-Disposition”,
“attachment; filename=testFileName_” + timeStamp + “.fileextention”);
// Set the HTTP MIME type of the output stream
Response.ContentType = “application/octet-stream”;
// Write the data
Response.BinaryWrite(byteArray);
Response.End();
}
Ha-P Coding