asp 文件下载
来源:互联网 发布:lua nginx set 编辑:程序博客网 时间:2024/06/10 07:47
public void DownloadFile(string fileName)
{
string adminUploadFilePath = ConfigParameter.AdminUploadFilePath;
if (!string.IsNullOrEmpty(fileName))
{
string filePath = Path.Combine(string.Format(@"{0}/AlumniCommunication/files", adminUploadFilePath), string.Format(@"{0}", fileName));
FileInfo fileInfo = new FileInfo(filePath);//D:\项目\BHG\BHGAlumni\AlumniAssociation.Admin\Upload/AlumniCommunication/files\济大各地校友会.xlsx
if (fileInfo.Exists == true) //如果存在文件
{
byte[] buffer = new byte[1024 * 1024]; //每次读取1024 * 1024大小的数据
Response.Clear();
FileStream fs = File.OpenRead(filePath);
long dataToRead = fs.Length;
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName));
Response.AppendHeader("Content-Length", fs.Length.ToString());
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
while (dataToRead > 0)
{
int readLength = fs.Read(buffer, 0, buffer.Length);
Response.OutputStream.Write(buffer, 0, readLength);
Response.Flush();
dataToRead = dataToRead - readLength;
}
Response.Flush();
fs.Dispose();
Response.Close();
}
else
{
Response.Write("<script>alert('没有找到对应文件');</script>");
}
}
}
{
string adminUploadFilePath = ConfigParameter.AdminUploadFilePath;
if (!string.IsNullOrEmpty(fileName))
{
string filePath = Path.Combine(string.Format(@"{0}/AlumniCommunication/files", adminUploadFilePath), string.Format(@"{0}", fileName));
FileInfo fileInfo = new FileInfo(filePath);//D:\项目\BHG\BHGAlumni\AlumniAssociation.Admin\Upload/AlumniCommunication/files\济大各地校友会.xlsx
if (fileInfo.Exists == true) //如果存在文件
{
byte[] buffer = new byte[1024 * 1024]; //每次读取1024 * 1024大小的数据
Response.Clear();
FileStream fs = File.OpenRead(filePath);
long dataToRead = fs.Length;
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName));
Response.AppendHeader("Content-Length", fs.Length.ToString());
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
while (dataToRead > 0)
{
int readLength = fs.Read(buffer, 0, buffer.Length);
Response.OutputStream.Write(buffer, 0, readLength);
Response.Flush();
dataToRead = dataToRead - readLength;
}
Response.Flush();
fs.Dispose();
Response.Close();
}
else
{
Response.Write("<script>alert('没有找到对应文件');</script>");
}
}
}
1 0
- 下载文件 asp.net
- ASP.NET文件下载
- asp.net 文件下载
- asp.net 下载文件
- Asp.net 下载文件
- asp 文件下载代码
- asp.net文件下载
- Asp.net 文件下载
- ASP.NET 文件下载
- ASP.NET 下载文件
- ASP文件下载代码
- asp.net下载文件
- Asp.Net 文件下载
- ASP.NET 文件下载
- ASP.NET下载文件
- ASP.NET下载文件
- asp.net下载文件
- ASP.NET文件下载
- dispatchTouchEvent()、onInterceptTouchEvent()和onTouchEvent()的关联 (一)
- 第四周 项目2-长方形面积
- Verilog语法_4(Modelsim自动化仿真)
- mac装win10后快捷键失灵
- ASCII码对照表
- asp 文件下载
- poj 3169 Layout(差分约束)
- PowerDesigner16配置显示注释comment配置方法
- 四、oracle 用户管理二
- 第4周项目-1建立单链表
- Android中BitmapFactory.Options详解
- 微信应用号
- SQL坑爹的地方
- Failed to load JavaHL Library. These are the errors that were encountered