Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
How to perform page refresh after Response.OutputStream.Write
This is the code

C#
byte[] content = dr["FileContent"] as byte[];
                string filename = dr["FileName"].ToString();
                Response.Clear();
                Response.ClearContent();
                Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
                Response.AddHeader("Content-Length", content.Length.ToString());
                Response.OutputStream.Write(content, 0, content.Length);   

pls help me.......

if i use the
C#
response.redirect("sucess.aspx")

the page is redirected suddenly....but i want to save the file and then the page is redirected to another page..

help me...how to redirect after the SaveAs dialog is opened......
Posted
Updated 18-Mar-12 23:54pm
v4

Hi,
Try this

Page.Response.Redirect(Page.Request.Url.ToString(), true);

Alternatively you can
XML
have only two ways of forcing a refresh. One is Javascript

setTimeout("location.reload(true);", timeout);
The second is a Meta tag:

<meta http-equiv="refresh" content="600">
 
Share this answer
 
Hi,

To download file you can use window.open method. execute your download code

C#
byte[] content = dr["FileContent"] as byte[];
                string filename = dr["FileName"].ToString();
                Response.Clear();
                Response.ClearContent();
                Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
                Response.AddHeader("Content-Length", content.Length.ToString());
                Response.OutputStream.Write(content, 0, content.Length);


in new window by window.open and refresh or redirect you original page.

this will work. i tried this in my one project and it was worked for me.
 
Share this answer
 
Comments
saravana__ 19-Mar-12 6:05am    
pls say how to use the window.open method
[no name] 19-Mar-12 9:23am    
using javascript www.w3schools.com/jsref/met_win_open.asp
[no name] 19-Mar-12 9:23am    
http://www.google.co.in/url?sa=t&rct=j&q=window.open%20in%20javascript&source=web&cd=3&sqi=2&ved=0CEIQFjAC&url=http%3A%2F%2Fwww.javascript-coder.com%2Ffiles%2Fwindow-popup%2Fjavascript-window-open-example1.html&ei=MjNnT7DAHcrirAe1vKC9Bw&usg=AFQjCNFFlEJytlG5lS-0Kt75GiClvGaQ0w&cad=rja
My response.write code runs in the end of the code.
But you are redirecting in the end.
I am afraid this is not possible.But you can search may be it have some way..
 
Share this answer
 
From your query and the code I can understand that you want to refresh the page after the file is downloaded. Since HTTP is stateless, you can detect if it is downloaded successfully. But I would suggest you to redirect to the same page.

After the Response.OutputStream.Write(content, 0, content.Length) line, add the below line.


C#
this.Response.Redirect(Request.Url.AbsolutePath);
 
Share this answer
 
Comments
saravana__ 19-Mar-12 2:56am    
This code not work for me
saravana__ 19-Mar-12 3:02am    
the code is just redirect the current page but the files are not download

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900