I already know, codes after the Response.End() will not work. I am trying to alert a message box after Response.End. Basically what i am doing is i will read data from Excel file and check for the missing data in the excel file. I will collect all the data that was missing from the Excel file and write them all to a text file and will prompt that using the following code
string strPath = Server.MapPath("ErrorLog") + "\\" + "ErrorLog.txt";
string FileName = "Errorlog" + ".txt";
string[] createText = { sb.ToString() };
File.WriteAllLines(strPath, createText);
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + "");
strPath.Length.ToString());
HttpContext.Current.Response.ContentType = "application/text";
HttpContext.Current.Response.WriteFile(strPath);
HttpContext.Current.Response.End();
After this i would like to display an alert box saying some thing like Invalid Data. But i would like to know how can i do that after Response.End
// Updated code as per lcarus
string strPath = Server.MapPath("ErrorLog") + "\\" + "ErrorLog.txt";
string[] createText = { sb.ToString() };
File.WriteAllLines(strPath, createText);
ClientScriptManager CSM = Page.ClientScript;
string strconfirm = "<script>if(window.confirm('Excel file has Invalid data.')){window.location.href='/Excel1/ErrorLog/ErrorLog.txt'}</script>";
CSM.RegisterClientScriptBlock(this.GetType(), "Confirm", strconfirm, false);
You need to do this in sort of 2 parts:
Collect the missing data, save it to a file (By the way, you need to create a unique name for the log file unless you are planning to support only one concurrent user on your site) and use
ClientScript.RegisterStartupScriptto call a function like this:You will know
path_to_log_filesince you are the one generating it on the server side.The user will see the alert and after clicking “OK” the log file will be displayed on his browser or asked to download it, depending on whether the browser knows how to handle the file (this is usually determined by the extension of the file).
UPDATE
Sample HTTPHandler implementation.
You can construct the link like this from code behind: