How to use AspnetUpload™ in your web application

 

 

26 April 2005

AspnetUpload™ is an ASP.NET HttpModule that make your web application to upload large file(s) to your web server with realtime progress indicator and no client software or control installation needed. To use this httpmodule in your web application, follow these steps:

  1. Copy Bestcomy.Web.Controls.Upload.dll to your project bin folder.

  2. In your project, under the Project menu, select the "Add Reference..." option. Use the Browse button to find Bestcomy.Web.Controls.Upload.dll, and click OK. This will include all the functionality of AspnetUpload™ into your project.

  3. In your project web.config, which located root of your web application. Add a line in the httpModules section of web.config like this:
    <httpModules>
         <add name="UploadModule" type="Bestcomy.Web.Controls.Upload.UploadModule,Bestcomy.Web.Controls.Upload" />
    </httpModules>

  4. In the same web.config, beneath configuration tag directly, add AspnetUpload™ configuration settings like this:

    <configSections>
    <section name="aspnetUploadSettings" type="System.Configuration.NameValueFileSectionHandler,System, Version=1.0.5000.0, Culture=neutral,PublicKeyToken=b77a5c561934e089" />
    </configSections>

    <aspnetUploadSettings>

    <!--
    Key Name: lisenceKey
    Valid Value: Purchased lisence key from the control author.
    -->
    <add key="lisenceKey" value="Lisence key purchase from www.aspnetupload.net" />

    <!--
    Key Name: maxRequestLength
    Valid Value: KBytes size of maximum upload file length to accept
    -->
    <add key="maxRequestLength" value="409600" />

    </aspnetUploadSettings>

  5. In your webform's client side(somename.aspx), which needs upload function, add enctype="multipart/form-data" to the form tag like this:
    <form id="Form1" method="post" enctype="multipart/form-data" runat="server">

  6. Add html file control in your webform's client side like this:
    <input type="file" name="file1">
    please do not use runat="server" attribute in this html file control.

  7. Add a using Bestcomy.Web.Controls.Upload; entry to the form code.

  8. Add following code to into Page_Load method:

    AspnetUpload upldr = new AspnetUpload();
    upldr.RegisterModelessProgressBar("ProgressBar.aspx",btn_upload);
    string fpath = Path.Combine(Server.MapPath("."),"Upload");
    if(!Directory.Exists(fpath))
        Directory.CreateDirectory(fpath);
    upldr.set_UploadFolder(fpath);


    Above code needs adding a using System.IO; entry to the form code, because above code use some file operation.

  9. You can use following code to get the uploaded file and save it to the destination folder:

    AspnetUpload upldr = new AspnetUpload();
    UploadFile file = upldr.GetUploadFile("file1");
    if(file != null)
    {
        string fpath = Path.Combine(Server.MapPath("."),"Upload");
        fpath = Path.Combine(fpath,Path.GetFileName(file.get_FileName()));
        file.SaveAs(fpath);
    }

You can get more example in my demo source.

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值