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:
-
Copy Bestcomy.Web.Controls.Upload.dll to your project bin folder.
-
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.
-
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> -
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> -
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"> -
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. -
Add a using Bestcomy.Web.Controls.Upload; entry to the form code.
-
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. -
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.