.net中实现附件下载功能的源码
答案:2 悬赏:40 手机版
解决时间 2021-03-04 05:33
- 提问者网友:人生佛魔见
- 2021-03-03 20:57
本人在开发一个网站,要求有实现提供附件下载的功能,却不知道应该如何写代码,本人所使用的开发工具是VS2005,开发语言是C#,请大侠们帮帮忙,如有知道的敬请回复,在此先行致谢了。
最佳答案
- 五星知识达人网友:躲不过心动
- 2021-03-03 22:02
public void FileDownload(string strFullName)//下载文件绝对路径
{
FileInfo DownloadFile = new FileInfo(strFullName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition","attachment;filename="+HttpUtility.UrlEncode(DownloadFile.Name,System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length",DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);//DownloadFile.FullName保存文件名
Response.Flush();
Response.End();
}
{
FileInfo DownloadFile = new FileInfo(strFullName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition","attachment;filename="+HttpUtility.UrlEncode(DownloadFile.Name,System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length",DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);//DownloadFile.FullName保存文件名
Response.Flush();
Response.End();
}
全部回答
- 1楼网友:狂恋
- 2021-03-03 22:16
其实下载就是一个连接,在html页面上的a标签,
比如你要下载那个,你可以这样<a href="周工作安排表.xls">周工作安排表</a>
这样你点击了就相当于下载了!
对于href="这里面要相对路径正确才行!"
有问题可以继续!
呵呵,希望能够帮到你!
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯