I have this function that works correctly as is. When called - it creates a file into my browser's download folder:
private void gvLots_Export(string fileName)
{
Response.Clear();
Response.AppendHeader("content-disposition", "attachment; filename=" + fileName );
Response.ContentType = "text/plain";
Response.Write(fichierExport.Contenu);
Response.End();
}
But now, I need to refresh the page just after that file is correctly added to the download folder. I have tried this:
Response.AppendHeader("content-disposition", "attachment; filename=" + fileName );
Response.ContentType = "text/plain";
Response.Write(fichierExport.Contenu);
Response.End();
Response.Redirect(Request.RawUrl);
However, it does not work for obvious reasons: the header is already sent, you can't redirect after Response.End().
I tried to add a variable into the header that could be retrieved by Resquest["stop"] (as seen below):
Response.AppendHeader("content-disposition", "?stop=true&" + "attachment; filename=" + fichierExport.NomFichier );
But these results are even worse. It does not refresh the page or download anything, but it shows me the content of the file I'm trying to download into the browser... is it even possible to download something and refresh the page in the same function... without having to ask the client to push 2 different buttons?