您的位置:首页 > 编程语言 > ASP

ASP.NET从服务器下载文件的原代码

2008-02-28 17:32 330 查看
protected void btnDownLoad_Click(object sender, EventArgs e)
{
resumeInfo = bresume.GetByUserId(CurrentUser.User_ID); //获取要下载的文件信息
string strAttachment = resumeInfo.AttachmentPath; //获取下载的文件名称
string strAttachmentPath = Server.MapPath("~/AttachmentPath/"); //获取文件名的服务器路径
if ((strAttachment == "") || !(File.Exists(strAttachmentPath + strAttachment)))
{
base.Alert(Resources.HRMSResource.FileExist,this.litMessage);
}
else
{
FileInfo DownloadFile = new FileInfo(strAttachmentPath + strAttachment);
this.Response.Clear();
this.Response.ClearHeaders();
this.Response.Buffer = false;

this.Response.ContentType = "application/octet-stream";
this.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
this.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
this.Response.WriteFile(DownloadFile.FullName);
this.Response.Flush();
this.Response.End();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: