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();
}
}
{
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();
}
}
相关文章推荐
- 下载Excel文件ASP.NET 代码
- ASP.NET实现从服务器下载文件问题处理
- Asp.net 2.0 GridView数据导出Excel文件(示例代码下载)
- asp.net 多文件上传,兼容IE6/7/8,提供完整代码下载
- asp.net Web Services上传和下载文件(完整代码)
- asp.net下载大文件代码
- 【ASP.NET】获取服务器文件夹内所有文件,并生成下载链接
- ASP.NET 大文件下载的实现思路及代码
- 转载:Asp.net 2.0 用C# 创建 PDF文件[引用] (示例代码下载)
- ASP.NET 文件下载代码
- Asp.net 2.0 用C# 创建 PDF文件[引用] (示例代码下载)
- ASP.NET 2.0 HttpHandler实现对某种文件类型权限保护(示例代码下载)
- Asp.net 2.0 文件下载[支持多线程, 断点续传功能](示例代码下载)
- Asp.net 2.0 GridView数据导出Excel文件(示例代码下载)
- (转)ASP.NET 2.0 读取配置文件[INI](示例代码下载)
- ASP.NET中下载文件的几种实例代码
- Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
- Asp.net 2.0 GridView数据导出Excel文件(示例代码下载)
- ASP.NET 从服务器下载文件