open memorystream with Excel then close the asp.net form

Moipickenisse

New Member
I have the following method that receive a Memorystream (Comma separated file). I get the popup window for excel and user can save, or open with excel. this part works perfectly. I'd like to close the original form after, or even before showing the excel dialog. it's written with C# 4.5, so i can use asyn, await as well. Any help would be greatly appreciated\[code\] protected void SendOutFile(MemoryStream MS, string FileName) { Byte[] streamFile = new Byte[MS.Length]; MS.Read(streamFile, 0, (int)MS.Length); Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "text/csv"; Response.AddHeader("Content-Disposition", string.Format("inline; filename={0}.csv", FileName)); Response.Charset = string.Empty; Response.OutputStream.Write(streamFile, 0, streamFile.Length); Response.OutputStream.Flush(); Response.OutputStream.Close(); Response.End();// close the currnet Form ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "CloseWin", "window.onfocus = function(){window.close();return false;}", true); }\[/code\]
 
Back
Top