Reputation: 3316
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?
Upvotes: 1
Views: 1083
Reputation: 3316
I assume what i'm asking for cannot be done... I didn't see anything like what i'm trying to do on any internet page. I'll make another hyperLink that just refresh the page and i'll ask all the customers to click on it after they download...
Upvotes: 1
Reputation: 793
Since I can't comment yet, I will post this here.
Look at: Refresh Page C# ASP.NET. Have you tried doing it the way described in the link? e.g.:
Response.Redirect(Request.Url.ToString(), true);
As described here, the RawUrl
only contains the part of the URL after the domain information and the Url
contains everything.
Upvotes: 1