现在的位置: 首页 > 综合 > 正文

asp.net处理大文件上传

2013年11月15日 ⁄ 综合 ⁄ 共 560字 ⁄ 字号 评论关闭

asp.net处理大文件上传

    public class HttpUploadHandler : IHttpHandler
    {
         #region IHttpHandler Members

          public bool IsReusable
          {
              get { return true; }
          }

          public void ProcessRequest(HttpContext context)
          {

              HttpWorkerRequest req = (HttpWorkerRequest)((IServiceProvider)context).GetService(typeof(HttpWorkerRequest));

              byte[] bts = new byte[2048];

               
            
              FileStream f = new FileStream("D:\\11.rmvb", FileMode.OpenOrCreate, FileAccess.Write); 
              int c = req.ReadEntityBody(bts, 2048); // 每次读2048字节
              
              while (c > 0)
              {
                  f.Write(bts, 0, c); // 写入文件
                  c = req.ReadEntityBody(bts, 2048);
              }
              f.Close();
              context.Response.Write("OK");
              context.Response.End(); 
          }

          #endregion
    }

抱歉!评论已关闭.