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();
}
}
本文介绍了一个简历下载功能的具体实现过程,包括从服务器获取文件、设置响应头以允许浏览器下载文件等步骤。通过ASP.NET和C#语言实现了用户点击下载按钮后能够下载其简历的功能。

被折叠的 条评论
为什么被折叠?



