欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net 文件下载实现代码

程序员文章站 2024-03-11 20:31:49
复制代码 代码如下:/// /// 文件下载 /// ///
复制代码 代码如下:

/// <summary>
/// 文件下载
/// </summary>
/// <param name="savename">文件名</param>
/// <param name="fullfilename">文件全名</param>
/// <param name="response">response</param>
public static void savefile(string savename,string fullfilename,system.web.httpresponse response)
{
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="+ system.web.httputility.urlencode(savename,system.text.encoding.utf8));
response.appendheader("content-length", downloadfile.length.tostring());
response.writefile(downloadfile.fullname);
response.flush();
response.end();
}
else
{
//文件不存在
}
}
catch
{
//文件不存在
}
}