怎样恢复能在asp.net中使用c#下载文件 – 最好的方法(对于大文件也是如此)
发布时间:2020-05-28 04:26:23 所属栏目:asp.Net 来源:互联网
导读:看下面的处理程序: using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace FileExplorer{ /// summary /// Summary description for HandlerForMyFE /// /summ
|
看下面的处理程序: using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace FileExplorer
{
/// <summary>
/// Summary description for HandlerForMyFE
/// </summary>
public class HandlerForMyFE : IHttpHandler,System.Web.SessionState.IRequiresSessionState
{
private HttpContext _context;
private HttpContext Context
{
get
{
return _context;
}
set
{
_context = value;
}
}
public void ProcessRequest(HttpContext context)
{
Context = context;
string filePath = context.Request.QueryString["Downloadpath"];
filePath = context.Server.MapPath(filePath);
if (filePath == null)
{
return;
}
System.IO.StreamReader streamReader = new System.IO.StreamReader(filePath);
System.IO.BinaryReader br = new System.IO.BinaryReader(streamReader.BaseStream);
byte[] bytes = new byte[streamReader.BaseStream.Length];
br.Read(bytes,(int)streamReader.BaseStream.Length);
if (bytes == null)
{
return;
}
streamReader.Close();
br.Close();
string fileName = System.IO.Path.GetFileName(filePath);
string MimeType = GetMimeType(fileName);
string extension = System.IO.Path.GetExtension(filePath);
char[] extension_ar = extension.ToCharArray();
string extension_Without_dot = string.Empty;
for (int i = 1; i < extension_ar.Length; i++)
{
extension_Without_dot += extension_ar[i];
}
//if (extension == ".jpg")
//{ // Handle *.jpg and
// WriteFile(bytes,fileName,"image/jpeg jpeg jpg jpe",context.Response);
/ |
相关内容
- asp.net – HttpWebRequest正在为404抛出异常
- asp.net-mvc – ASP.NET MVC中的通用基本控制器错误处理问题
- file-upload – 增加Kestrel的上传请求长度限制
- asp.net – 增加会话TimeOut
- asp.net-mvc – 同时发送文件并重定向到新页面的MVC方式是什
- ASP.NET用户控件列表/集合/数组属性
- asp.net – 在没有Global.asax的情况下处理应用程序范围的事
- 为什么我的IIS7应用程序池在从ASP.NET页面调用的DLL中发生异
- 在应用程序配置中找不到LocalSqlServer或连接字符串为空
- asp.net-mvc-2 – 什么时候使用View()与RedirectToAction
推荐文章
站长推荐
- asp.net-mvc – ASP.NET MVC JavaScript路由
- asp.net-core – 对Post请求的两次调用:使用htt
- asp.net-mvc – 单元测试ASP.Net MVC Action结果
- asp.net-mvc – 如何获取Azure网站上的错误详细信
- 你使用ASP.NET MVC Action方法做了什么聪明的事情
- asp.net-mvc – 实体框架SQLite部署
- asp.net-mvc-3 – FluentValidation入门问题
- asp.net – 编译器失败,错误代码为-1073741819
- asp.net – 在web.config中添加程序集引用
- asp.net gridview复选框选择
热点阅读
