views:

36

answers:

4

Hi;

My goal is to redirect or refresh my page while downloding excel file :

Details :

In my application i am sending dynamically generated excel file

setContentType("application/vnd.ms-excel; charset=windows-1254");
setCharacterEncoding(Constants.ENCODING);
setHeader("content-disposition", "attachment;filename=" + Constants.DEFAULT_EXCEL_FILE);
setHeader("Location","http://www.google.com");

But after asking user to save or open excel file, it didn't redirect to ex : google.com.

Is it possible to do it in header part ? If yes please say how .

Thanks.

A: 

you cannot redirect,because you have flushed out the response stream.

Suresh S
I think you meant that he **cannot do it**. And, even if the OP writes both headers and flushes the response stream, he will not be able to achieve what he desires.
Vineet Reynolds
A: 

This is simply isn't possible for the reason that the defined behavior of the browser is bound to be vague. In other words, when the browser notes the presence of two headers, each with possibly conflicting requirements, then the behavior might be to simply ignore one, instead of obeying both - it is upto the browser vendor to define this.

In this particular case, the Content-Disposition and the Location HTTP headers are conflicting, more so because if the browser were to process the Location header first resulting in the redirection, the end-user would never be prompted for the file download.

On an additional note, the Location header would only make sense for a HTTP 302 response (I believe that this is not the case in your application, not that it might help).

Vineet Reynolds
A: 

You could use some JavaScript for the job

<a href="myfile.txt" onclick='window.location = 'http://www.google.com/';"&gt;
File
</a>

Tim
A: 

This is one option, not in header part tough

private void DownloadFile()

{

//Download file here...

//Refresh this page.
this.Response.Redirect(Request.Url.AbsolutePath);

}
Aamod Thakur