Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everybody,

I have used Response.Flush() with Response.End() to download file in my application .But when some body downloads the file (execution of Response.Flush)
ends the connection between client side(.aspx) and server side(.cs).My problem is i am refreshing the page from .aspx by "http-equiv=Refresh" to redirect to another page.

Since there is no connection in between client side and server side,no redirection happens..

Can anybody have any idea how to download the file(from dataset to some customized loacl path) with out breaking the connection between the server side and client side..

Appreciate your HELP!!!

Cheers,

Sugato
Posted
Updated 27-Sep-11 15:37pm
v3

1 solution

C#
if (ds.Tables[0].Rows.Count != 0)
            {
                for (i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    strFileContents = strFileContents + " " + ds.Tables[0].Rows[i]["UserName"] + " " + ds.Tables[0].Rows[i]["SearchDate"] + " " + ds.Tables[0].Rows[i]["Reference"] + " " + ds.Tables[0].Rows[i]["CaseType"] + " " + ds.Tables[0].Rows[i]["SearchName"] + " " + ds.Tables[0].Rows[i]["Location"] + System.Environment.NewLine;
                }
                Downloaded(strFileContents);
                string strFilePath = "./downloads/filename.txt";
                Response.AppendHeader("Content-Disposition", "attachment; filename=" + strFilePath);
                Response.WriteFile(strFilePath);
                Response.End();
            }




C#
public void Downloaded(string strFileContents)
   {
       string strFilePath = Server.MapPath("./downloads/billing.txt").ToString();

       if (!File.Exists(strFilePath))
       {
           File.Create(strFilePath).Close();
       }
       StreamWriter sw = File.CreateText(strFilePath);
       sw.WriteLine(strFileContents);
       sw.WriteLine(sw.NewLine);
       sw.Flush();
       sw.Close();
   }
 
Share this answer
 
Comments
Sugato Pal 27-Sep-11 6:03am    
Still the probelm persist..i cannot use Response.End .Coz it kills all the connection between .aspx and dll .

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