ASP.NET如何实现下载?
点击的时候就可以下载?这个怎么弄呢?那个下载是一个超链接来的
我希望通过点击,然后传给一般处理程序实现下载,怎么弄呢? --------------------编程问答-------------------- 传给一般处理程序实现下载
什么意思? --------------------编程问答-------------------- 这个文件的位置不就可以了吗 <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而不是下载我想要的文件 --------------------编程问答--------------------
直接放文件路径,如果你是问后台的话:
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而不是下载我想要的文件 --------------------编程问答--------------------
这个文件的位置不就可以了吗 <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而不是下载我想要的文件
路径你要按自己情况改啊。。。哪能完全照抄 --------------------编程问答-------------------- 参考:http://www.cnblogs.com/qiangni/archive/2012/12/12/2814585.html
补充:.NET技术 , C#