c#下载文件的疑问 谢谢 在浏览器上点击“下载”按钮,就将服务器的一个文件下载到本地,保存成.txt形式,该怎么保存成.txt形式,并让用户选择保存路径?谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 protected void Button1_Click( object sender, System.EventArgs e ) { Response.Clear(); Response.Buffer = true; Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.txt"); Response.WriteFile("xxxxx.txt"); Response.Flush(); Response.End(); } string fileName = "";//客户端保存的文件名 string filePath = Server.MapPath("");//路径 FileInfo fileInfo = new FileInfo(filePath); Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName); Response.AddHeader("Content-Length", fileInfo.Length.ToString()); Response.AddHeader("Content-Transfer-Encoding", "binary"); Response.ContentType = "application/octet-stream"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); Response.WriteFile(fileInfo.FullName); Response.Flush(); Response.End(); //字符流方式下载文件 protected void Button4_Click(object sender, EventArgs e) { string fileName = "";//客户端保存的文件名 string filePath = Server.MapPath("");//路径 //以字符流的形式下载文件 FileStream fs = new FileStream(filePath, FileMode.Open); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); } 关于sql里,insert数据的时候,数据里面包含单引号 点按钮弹出新页面 關於一個層的問題。。望高手指教下 我想从一个表中随即读出10条记录,相关sql语句该怎么写啊?哪位高手指点一二? 弱弱的问,怎么对xml文件的节点属性进行查询? 时钟问题 在线等,急。有关Win2003Server系统下IIS6.0、VS.NET2003开发环境的问题。回答满意者额外送200-300分! 请高手提供点思路? 插入 在线考试系统的登陆问题 如何完全卸载visual studio 2010 用户自定义页面实现方法
{
Response.Clear();
Response.Buffer = true;
Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.txt");
Response.WriteFile("xxxxx.txt");
Response.Flush();
Response.End(); }
string filePath = Server.MapPath("");//路径 FileInfo fileInfo = new FileInfo(filePath);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.WriteFile(fileInfo.FullName);
Response.Flush();
Response.End();
//字符流方式下载文件
protected void Button4_Click(object sender, EventArgs e)
{
string fileName = "";//客户端保存的文件名
string filePath = Server.MapPath("");//路径 //以字符流的形式下载文件
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}