asp.net实现文件下载(wap手机下载)
来源:互联网 发布:天府广场附近美食 知乎 编辑:程序博客网 时间:2024/04/27 13:28
这个问题困扰了我两天,手机下载
protected void Page_Load(object sender, EventArgs e)
{
string filename = Server.UrlDecode(Request["upload"]);
string filePath = Server.MapPath("upload/" + filename);//路径
FileDownload(filePath);
}
/// <summary>
/// 文件下载
/// </summary>
/// <param name="FullFileName"> </param>
private void FileDownload(string FullFileName)
{
try
{
FileInfo DownloadFile = new FileInfo(FullFileName);
if (DownloadFile.Exists)
{
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
//Response.ContentType = "application/octet-stream";//通知浏览器下载文件而不是打开
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
switch (DownloadFile.Extension.ToLower())//这是必须,电脑上浏览就不需要
{
case ".pdf":
Response.ContentType = "application/pdf";
break;
case ".txt":
Response.ClearHeaders();
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.ASCII));
Response.ContentType = "text/plain";
break;
case ".jpg":
Response.ContentType = "image/jpeg";
break;
case ".doc":
Response.ContentType = "application/msword";
break;
case ".zip":
Response.ContentType = "application/zip";
break;
case ".rar":
Response.ContentType = "application/rar";
break;
case ".xls":
//Response.ContentType = "application/xls";
Response.ContentType = "application/vnd.ms-excel";
break;
default:
Response.ContentType = "application/unknown";
break;
}
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}
else
{
Label1.Text="文件名不存在";
}
}
catch(Exception ex)
{
Label1.Text = "aa";
Label1.Text = ex.Message;
}
}
- asp.net实现文件下载(wap手机下载)
- ASP.NET实现文件下载
- ASP.NET实现文件下载
- ASP.NET实现文件下载
- asp.net实现文件下载
- ASP.NET实现文件下载
- asp.net 实现文件下载
- ASP.net实现文件下载
- ASP.NET实现文件下载
- asp.net文件下载,实现隐藏文件下载地址
- asp.net下载文件实现代码
- asp.net 实现数据流文件下载
- asp.net 文件下载实现代码
- Asp.net 实现断点续传 下载大文件
- asp.net中实现文件下载功能
- Asp.net 实现PDF文件下载
- ASP.net 实现文件强制下载
- asp.net中实现文件下载功能
- Posix多线程编程整理
- directshow动态改变媒体类型Dynamic Format Changes
- 常用Linux命令组合使用方式
- 大型复杂系统性能测试初步分析评估的核心思路
- 大三上学期杂谈
- asp.net实现文件下载(wap手机下载)
- 【Stones from other hills】手机视频监控系统小结 收藏
- android kernel+busybox
- Android G1 JAVA虚拟机
- String()与string()是一样的
- 为自己的网站添加RSS功能
- TCPMP绘制视频画面的位置
- 行转列通用过程
- 如何查看sql的执行计划