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

一,下载组件到项目的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)));
            }

        }


感谢两位前辈提供这么好的东西

posted on 2005-11-28 11:10  昊子  阅读(2771)  评论(14编辑  收藏  举报

导航