WebbHttpModule
文件上传控件——WebbUpload [转自http://www.cnblogs.com/sjpisaboy/archive/2006/04/06/368410.aspx]
2007-11-07 16:49
这里介绍的是一款文件上传控件。这款控件是由我们国人自己开发的,而功能则堪比ASPNETUPLOAD和SunriseUpload。关于作者可访问他的BLOG:http://wucountry.cnblogs.com/
我在这里只是抛砖引玉,介绍这款控件的基本功能和用法罢了。 可能有人会说,文件上传控件不是有<input type="file">为什么吗?是的,但首先它是个客户端的控件,如果把它直接设为服务器端控件(加入runat="server"属性),貌似可以用,可问题却颇多。这里就不多说这个控件的不是了,不相信的同志大可不予理睬。 你先到http://wucountry.cnblogs.com/archive/2005/12/28/306725.aspx上面去下载这个控件,取得DLL文件并把它加入引用。接下来就在.aspx中,添加一个<input type="file">控件,代码如下: 1<form id="Form1" method="post" encType="multipart/form-data" runat="server">
2 <input id="ifUp1" contentEditable="false" type="file" name="ifUp1"> 3</form> 这段代码中要注意,encType="multipart/form-data"这个属性一定要加入。另外,input中不必加入runat="server"。完成了这步之后,你可以在用于触发上传文件的button中绑定两个事件处理函数。 1private void ibtnSend_Load(object sender, System.EventArgs e)
2 { 3 ImageButton ibtnSender = (ImageButton)sender; 4 WebbUpload webbUpload = new WebbUpload(); 5 webbUpload.RegisterProgressBar(ibtnSender); 6 } 7 8private void ibtnSend_Click(object sender, System.Web.UI.ImageClickEventArgs e) 9 { 10string uploadFolder = MapPath(@"Upload\"); 11 WebbUpload webbUpload = new WebbUpload(); 12 UploadFile ifUp1 = webbUpload.GetUploadFile("ifUp1"); 13 14if (ifUp1 != null) 15 { 16 string fileName1 = Path.GetFileName(ifUp1.ClientFullPathName); 17 ifUp1.SaveAs(uploadFolder + newFileName); 18 } 19 } 20 不要忘了在.cs文件中声明这个命名空间:using Webb.WAVE.Controls.Upload; 有时候可能出现UploadFile ifUp1 = webbUpload.GetUploadFile("ifUp1");这句话中的ifUp1返回一个空引用。这是由于你没有在web.config中加入下面这句: 1<!-- Settings of WebbUpload -->
2 <httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="1024000" executionTimeout="900" /> 3 <httpModules> 4 <add name="WebbHttpModule" type="Webb.WAVE.Controls.Upload.WebbHttpModule, Webb.WAVE.Controls.Upload"/> 5 </httpModules> 6 <httpHandlers> 7 <add verb="*" path="progress.ashx" type="Webb.WAVE.Controls.Upload.WebbUploadStatusHandler, Webb.WAVE.Controls.Upload" /> 8 </httpHandlers> 9 <!-- ========================= --> 以及在form中加入那句encType="multipart/form-data"。 |