复制代码 代码如下:
/// <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
{
//文件不存在
}
}
/// <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
{
//文件不存在
}
}
标签:
asp.net,文件下载
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com
暂无“asp.net 文件下载实现代码”评论...