All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
学习动态网页技术PHP中错误处理的一些方法_php资料_编程技术
C#教程:使用Visual Studio 2005 创建项目
Asp.net的HttpCookie写入汉字读取时为乱码的解决方法_.net资料_编程技术
SQL循序渐进(5)-------插入数据到表_[SQL,Server教程]
HTML语言剖析(十三)其他标记_[Html教程]_0
C#教程:将应用软件的使用次数写入注册表
将GridView内容导出到Excel或Word中_[Asp.Net教程]
ASP.NET,2.0之ObjectDataSourc控件_[Asp.Net教程]
SQL存储过程入门级教程_[SQL Server教程]
visual c++中的画笔类CPen使用实例
Reading number is top 10 pictures
西方气质的东方美女1
The world's ten biggest attractions of inventory super the moon
英雄联盟超神十连杀截图
Ashlynn Brooke show proud chest measurement2
NeedWallpaper1
2012 national geographic daily picture8
2012 national geographic daily picture9
NeedWallpaper13
这才是真正的人体艺术2
A man's favorite things15
Download software ranking
VC++6.0培训教程
Boxer Classic video2
linux初级教程
Boxer Classic video3
Boxer Classic video1
功夫熊猫2(上集)
Unix video tutorial6
Unix video tutorial14
Unix video tutorial12
Boxer vs Yellow2
aaa published in(发表于) 2013/12/6 10:24:30 Edit(编辑)
ASP.NET,应用中大文件上传研究_.net资料_编程技术

ASP.NET,应用中大文件上传研究_.net资料_编程技术

ASP.NET 应用中大文件上传研究_.net资料_编程技术-数科优化网
  在项目中经常要用到了大文件上传,要上传的文件有100多m,于是研究现在国内使用的大文件上传的组件发现用的比较多的有两个控件AspnetUpload 2.0和Lion.Web.UpLoadModule,两个控件的方法是:利用隐含的HttpWorkerRequest,用它的GetPreloadedEntityBody 和 ReadEntityBody方法从IIS为ASP.NET建立的pipe里分块读取数据。Chris Hynes为我们提供了这样的一个方案(用HttpModule),该方案除了允许你上传大文件外,还能实时显示上传进度。

  Lion.Web.UpLoadModule和AspnetUpload 两个.NET组件都是利用的这个方案。

  当上传单文件时,两个软件的方法是一样的,继承HttpModule


HttpApplication application1 = sender as HttpApplication;
HttpWorkerRequest request1 = (HttpWorkerRequest) ((IServiceProvider) HttpContext.Current).GetService(typeof(HttpWorkerRequest));
try
{
 if (application1.Context.Request.ContentType.IndexOf("multipart/form-data") <= -1)
 {
  return;
 }
 //Check The HasEntityBody
 if (!request1.HasEntityBody())
 {
  return;
 }
 int num1 = 0;
 TimeSpan span1 = DateTime.Now.Subtract(this.beginTime);

 string text1 = application1.Context.Request.ContentType.ToLower();

 byte[] buffer1 = Encoding.ASCII.GetBytes(("\r\n--" + text1.Substring(text1.IndexOf("boundary=") + 9)).ToCharArray());
 int num2 = Convert.ToInt32(request1.GetKnownRequestHeader(11));
 Progress progress1 = new Progress();

 application1.Context.Items.Add("FileList", new Hashtable());

 byte[] buffer2 = request1.GetPreloadedEntityBody();
 num1 += buffer2.Length;

 string text2 = this.AnalysePreloadedEntityBody(buffer2, "UploadGUID");
 if (text2 != string.Empty)
 {
  application1.Context.Items.Add("LionSky_UpLoadModule_UploadGUID", text2);
 }
 bool flag1 = true;
 if ((num2 > this.UpLoadFileLength()) && ((0 > span1.TotalHours) || (span1.TotalHours > 3)))
 {
  flag1 = false;
 }
 if ((0 > span1.TotalHours) || (span1.TotalHours > 3))
 {
  flag1 = false;
 }
 string text3 = this.AnalysePreloadedEntityBody(buffer2, "UploadFolder");
 ArrayList list1 = new ArrayList();
 RequestStream stream1 = new RequestStream(buffer2, buffer1, null, RequestStream.FileStatus.Close, RequestStream.ReadStatus.NoRead, text3, flag1, application1.Context, string.Empty);
 list1.AddRange(stream1.ReadBody);
 if (text2 != string.Empty)
 {
  progress1.FileLength = num2;
  progress1.ReceivedLength = num1;
  progress1.FileName = stream1.OriginalFileName;
  progress1.FileCount = ((Hashtable) application1.Context.Items["FileList"]).Count;
  application1.Application["_UploadGUID_" + text2] = progress1;
 }
 if (!request1.IsEntireEntityBodyIsPreloaded())
 {
  byte[] buffer4;
  ArrayList list2;
  int num3 = 204800;
  byte[] buffer3 = new byte[num3];
  while ((num2 - num1) >= num3)
  {
   if (!application1.Context.Response.IsClientConnected)
   {
    this.ClearApplication(application1);
   }
   num3 = request1.ReadEntityBody(buffer3, buffer3.Length);
   num1 += num3;
   list2 = stream1.ContentBody;
   if (list2.Count > 0)
   {
    buffer4 = new byte[list2.Count + buffer3.Length];
    list2.CopyTo(buffer4, 0);
    buffer3.CopyTo(buffer4, list2.Count);
    stream1 = new RequestStream(buffer4, buffer1, stream1.FileStream, stream1.FStatus, stream1.RStatus, text3, flag1, application1.Context, stream1.OriginalFileName);
   }
   else
   {
    stream1 = new RequestStream(buffer3, buffer1, stream1.FileStream, stream1.FStatus, stream1.RStatus, text3, flag1, application1.Context, stream1.OriginalFileName);
   }
   list1.AddRange(stream1.ReadBody);
   if (text2 != string.Empty)
   {
    progress1.ReceivedLength = num1;
    progress1.FileName = stream1.OriginalFileName;
    progress1.FileCount = ((Hashtable) application1.Context.Items["FileList"]).Count;
    application1.Application["_UploadGUID_" + text2] = progress1;
   }
  }
  buffer3 = new byte[num2 - num1];
  if (!application1.Context.Response.IsClientConnected && (stream1.FStatus ==  RequestStream.FileStatus.Open))
  {
   this.ClearApplication(application1);
  }
  num3 = request1.ReadEntityBody(buffer3, buffer3.Length);
  list2 = stream1.ContentBody;
  if (list2.Count > 0)
  {
   buffer4 = new byte[list2.Count + buffer3.Length];
   list2.CopyTo(buffer4, 0);
   buffer3.CopyTo(buffer4, list2.Count);
   stream1 = new RequestStream(buffer4, buffer1, stream1.FileStream, stream1.FStatus, stream1.RStatus, text3, flag1, application1.Context, stream1.OriginalFileName);
  }
  else
  {
   stream1 = new RequestStream(buffer3, buffer1, stream1.FileStream, stream1.FStatus, stream1.RStatus, text3, flag1, application1.Context, stream1.OriginalFileName);
  }
  list1.AddRange(stream1.ReadBody);
  if (text2 != string.Empty)
  {
   progress1.ReceivedLength = num1 + buffer3.Length;
   progress1.FileName = stream1.OriginalFileName;
   progress1.FileCount = ((Hashtable) application1.Context.Items["FileList"]).Count;
   if (flag1)
   {
    progress1.UploadStatus = Progress.UploadStatusEnum.Uploaded;
   }
   else
   {
    application1.Application.Remove("_UploadGUID_" + text2);
   }
  }
 }
 byte[] buffer5 = new byte[list1.Count];
 list1.CopyTo(buffer5);
 this.PopulateRequestData(request1, buffer5);
}
catch (Exception exception1)
{
 this.ClearApplication(application1);
 throw exception1;
}




添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.