📄 downloadfilehandler.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Krystalware.SlickUpload.Configuration;
using Krystalware.SlickUpload.Streams;
using System.IO;
public class DownloadFileHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
int id = int.Parse(context.Request.QueryString["id"]);
RepositoryFile file = RepositoryFile.GetById(id);
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
context.Response.AddHeader("Content-Length", file.Length.ToString());
context.Response.ContentType = "application/octet-stream";
using (Stream dataStream = file.GetDataStream())
{
byte[] buffer = new byte[8192];
int read;
while ((read = dataStream.Read(buffer, 0, 8192)) > 0)
context.Response.OutputStream.Write(buffer, 0, read);
}
}
public bool IsReusable
{
get
{
return true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -