当前位置:编程学习 > C#/ASP.NET >>

asp.net 文件下载实现代码

答案:
复制代码 代码如下:

/// <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 动态写入服务器端控件第1/2页
下一个:c# 读取文件内容存放到int数组 array.txt

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,