How to show a message and send a file using ASP.NET

Hoidogike

New Member
I generate a set of letters in a file, but if there are errors then the file may be incomplete. I want to send the file anyway, but with a warning to the user. So I have this:\[code\] string errMessage; string filePath = CCGTMarblox.Admin.Helpers.DocumentHelper.GenerateRejectionLetters(grantIDs, out errMessage); if (!String.IsNullOrEmpty(errMessage)) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "problem", String.Format("alert('{0}');", errMessage), true); } if (filePath != null) { System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath); Response.ClearHeaders(); Response.AddHeader("Content-Disposition", string.Format(@"attachment; filename=""{0}""", fileInfo.Name)); Response.AddHeader("Content-Length", fileInfo.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.TransmitFile(fileInfo.FullName); Response.Flush(); }\[/code\]The problem is that the the alert is not shown when the code to download the file is included - the headers are cleared and it's like a new Response. Is there any way I can send the script and the file? I tried to Response.Redirect to a page that retrieves the file, but that didn't work either.
 
Back
Top