您的位置:首页 > 其它

使用Lion.Web.UpLoadModule上传大文件心得

2008-08-21 13:31 746 查看
一,下载组件到项目的Bin目录下,(我上传的文件直接解压缩到bin目录即可)
/Files/pblee/bin.rar

二,在项目中添加引用
右点资源管理器的引用-添加引用-COM-选择-选择刚复制的dll文件-确定

三,在web.config中注册组件
打开web.config
在<system.web>和</system.web>之间添加

<httpModules>
<add name="UploadModule" type="Lion.Web.UpLoadModule.UpLoadModule, Lion.Web.UpLoadModule, Version=1.2.2004.805, Culture=neutral, PublicKeyToken=eee5fb5e935c316e" />
</httpModules>
<httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="100819200" executionTimeout="900"/>
上面的是注册组件
下面的是重设上传RequestLength

四,前台代码
提交的Form修改一下


<FORM id="Form1" method="post" enctype="multipart/form-data" runat="server">
文件的input


<INPUT contenteditable="false" type="file" name="file1">
五,后台代码
记得using


using Lion.Web.UpLoadModule;Page_Load根据需要修改


private void Page_Load(object sender, System.EventArgs e)






{


UpLoadHelper uh = new UpLoadHelper();


uh.RegisterProgressBar(Button1,true);


string path = Path.Combine(Server.MapPath("."),"UploadFile");


if(!Directory.Exists(path))


Directory.CreateDirectory(path);


uh.UploadFolder=path; //设置上传文件临时目录,要求ASPNET用户对该文件夹有写权限。


}


按钮事件


private void Button1_Click(object sender, System.EventArgs e)






{


string path = Path.Combine(Server.MapPath("."),"UploadFile");






UpLoadHelper uh = new UpLoadHelper();


foreach(UpLoadFile file in uh.GetUploadFileList("file1"))






{


file.SaveAs(Path.Combine(path,Path.GetFileName(file.FileName)));


}


}
转自:http://blog.csdn.net/cnming/archive/2008/03/18/2195203.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: