response.flush&的问题响应结束 [英] problem with response.flush & response.end

查看:73
本文介绍了response.flush&的问题响应结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我已经使用Response.Flush()Response.End()在我的应用程序中下载文件.但是当某些人下载文件时(执行Response.Flush)
结束客户端(.aspx)和服务器端(.cs)之间的连接.我的问题是我要通过"http-equiv=Refresh"从.aspx刷新页面以重定向到另一个页面.

由于客户端和服务器端之间没有连接,因此不会发生重定向..

任何人都可以在不中断服务器端和客户端之间的连接的情况下,将文件下载(从数据集下载到一些自定义的loacl路径)..

感谢您的帮助!
干杯,

Sugato

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

推荐答案

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();
            }









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();
   }


这篇关于response.flush&amp;的问题响应结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆