downloadfilehandler.cs
来自「大文件上传组件」· CS 代码 · 共 46 行
CS
46 行
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 + =
减小字号Ctrl + -
显示快捷键?