ASP.NET如何实现下载? 点击的时候就可以下载?这个怎么弄呢?那个下载是一个超链接来的我希望通过点击,然后传给一般处理程序实现下载,怎么弄呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个文件的位置不就可以了吗 <a href="http://.....//ssdsdsdsd.jpg"></a> 直接放文件路径,如果你是问后台的话:protected void Button1_Click(object sender, EventArgs e) { /* 微软为Response对象提供了一个新的方法TransmitFile来解决使用Response.BinaryWrite下载超过400mb的文件时导致Aspnet_wp.exe进程回收而无法成功下载的问题。 代码如下: */ Response.ContentType = "application/x-zip-compressed"; Response.AddHeader("Content-Disposition", "attachment;filename=CodeShark.zip"); string filename = Server.MapPath("DownLoad/CodeShark.zip"); Response.TransmitFile(filename); } 一般处理程序代码如下:public void ProcessRequest(HttpContext context) { if (context.Request["strPath"] != null && context.Request["strPath"].ToString() != "") { string strPath = context.Server.UrlDecode(context.Request["strPath"].ToString()); string strName = System.IO.Path.GetFileName(strPath); //以字符流的形式下载文件 FileStream fs = new FileStream(strPath, FileMode.Open); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); context.Response.ContentType = "application/octet-stream"; //通知浏览器下载文件而不是打开 context.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(strName, System.Text.Encoding.UTF8)); context.Response.BinaryWrite(bytes); context.Response.Flush(); context.Response.End(); } }下载两个字的代码如下:strSb.Append("<td><a href=\"DownLoadHandler.ashx?strPath=" + Server.UrlEncode(myFileInfo.FilePath) + "\">下载</a></td>");问题:为什么点那个下载的时候,就是下载DownLoadHandler.ashx而不是下载我想要的文件 一般处理程序代码如下:public void ProcessRequest(HttpContext context) { if (context.Request["strPath"] != null && context.Request["strPath"].ToString() != "") { string strPath = context.Server.UrlDecode(context.Request["strPath"].ToString()); string strName = System.IO.Path.GetFileName(strPath); //以字符流的形式下载文件 FileStream fs = new FileStream(strPath, FileMode.Open); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); context.Response.ContentType = "application/octet-stream"; //通知浏览器下载文件而不是打开 context.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(strName, System.Text.Encoding.UTF8)); context.Response.BinaryWrite(bytes); context.Response.Flush(); context.Response.End(); } }下载两个字的代码如下:strSb.Append("<td><a href=\"DownLoadHandler.ashx?strPath=" + Server.UrlEncode(myFileInfo.FilePath) + "\">下载</a></td>");问题:为什么点那个下载的时候,就是下载DownLoadHandler.ashx而不是下载我想要的文件 参考:http://www.cnblogs.com/qiangni/archive/2012/12/12/2814585.html 求教C#配合Tx Text Control制作类似Word审阅功能,就是江湖上传说的文字编辑痕迹 picturebox加载图片的问题,在线等,解决马上结贴 panel里的label背景问题。 ASP.NET 图片缩放占用内存问题 Remoting 技术 (不认识DataSet数据类型),Remoting高手请进 请教高手 c# 调用dns类怎么有时候报错 C# 数据库求帮助 C#修改记录的问题 应用程序正常初始化(Oxc000007b)失败 FTP检索服务器某文件夹下的所有文件时,得到的文件名带/,怎么解决? .net自学路线是什么呢 关于多线程的疑问,研究了一天,还是整不对!
{
/*
微软为Response对象提供了一个新的方法TransmitFile来解决使用Response.BinaryWrite下载超过400mb的文件时导致Aspnet_wp.exe进程回收而无法成功下载的问题。
代码如下:
*/
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=CodeShark.zip");
string filename = Server.MapPath("DownLoad/CodeShark.zip");
Response.TransmitFile(filename);
}
public void ProcessRequest(HttpContext context)
{
if (context.Request["strPath"] != null && context.Request["strPath"].ToString() != "")
{
string strPath = context.Server.UrlDecode(context.Request["strPath"].ToString());
string strName = System.IO.Path.GetFileName(strPath);
//以字符流的形式下载文件
FileStream fs = new FileStream(strPath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
context.Response.ContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(strName, System.Text.Encoding.UTF8));
context.Response.BinaryWrite(bytes);
context.Response.Flush();
context.Response.End();
}
}
下载两个字的代码如下:
strSb.Append("<td><a href=\"DownLoadHandler.ashx?strPath=" + Server.UrlEncode(myFileInfo.FilePath) + "\">下载</a></td>");
问题:为什么点那个下载的时候,就是下载DownLoadHandler.ashx而不是下载我想要的文件
public void ProcessRequest(HttpContext context)
{
if (context.Request["strPath"] != null && context.Request["strPath"].ToString() != "")
{
string strPath = context.Server.UrlDecode(context.Request["strPath"].ToString());
string strName = System.IO.Path.GetFileName(strPath);
//以字符流的形式下载文件
FileStream fs = new FileStream(strPath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
context.Response.ContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(strName, System.Text.Encoding.UTF8));
context.Response.BinaryWrite(bytes);
context.Response.Flush();
context.Response.End();
}
}
下载两个字的代码如下:
strSb.Append("<td><a href=\"DownLoadHandler.ashx?strPath=" + Server.UrlEncode(myFileInfo.FilePath) + "\">下载</a></td>");
问题:为什么点那个下载的时候,就是下载DownLoadHandler.ashx而不是下载我想要的文件