Upload large attachments # upload large attachments

Source: Internet
Author: User

We all know that the controls provided by vs2008 are relatively simple and easy to use, but they are subject to many restrictions, such as canceling the upload operation, uploading multiple files, and displaying the progress of the upload process, to solve these problems, we can use the third-party plug-in aspnetupload. I have found that both the books and online articles are incomplete or have problems, and I have studied the problems successfully.

Right-click the root directory of the website, select "add reference" from the shortcut menu, and click "add reference". Switch to "Browse" find the DLL file of the component "bestcomy. web. controls. upload. DLL "(This file can be downloaded from the official website www.aspnetupload.net. This document will also be available later), click" OK ", and return to the vs2008 work interface,

Web. config Configuration:
Add the following content to <configsections>:
<Section name = "aspnetuploadsettings" type = "system. configuration. namevaluefilesectionhandler, system, version = 2.2.0.60111, culture = neutral, publickeytoken = b77a5c561934e089"/>
Add the following to </appsections>:

<Aspnetuploadsettings>

<! --
Key name: lisencekey
Valid value: purchased lisence key from the control author.
-->
<Add key = "lisencekey" value = "erk5wdtrreegnx9gaj07fz7xj0cgnab9o"/>

<! --
Key name: maxrequestlength
Valid value: Kbytes size of maximum upload file length to accept
-->
<Add key = "maxrequestlength" value = "2048000"/>

</Aspnetuploadsettings>

At the beginning, I did not successfully add this old upload. value = "2048000" here, I can modify the corresponding value.

Find <Add name = "uploadmodule" type = "bestcomy. Web. Controls. Upload. uploadmodule, bestcomy. Web. Controls. Upload"/>

Upload the front-end code:
<Div>
<Input type = "file" name = "file1"/> <br/> // register this is an HTML control, and the names are all "file1 ".
<Input type = "file" name = "file1"/> <br/>
<Input type = "file" name = "file1"/> <br/>
<Asp: button id = "button1" runat = "server" text = "Upload" onclick = "button#click"/>
</Div>

Background code:
To add using system. IO; using bestcomy. Web. Controls. Upload; these two namespaces
Protected void page_load (Object sender, eventargs E)
{
String fpath = path. Combine (request. physicalapplicationpath, "uploadfiles ");
If (! Directory. exists (fpath ))
Directory. createdirectory (fpath );
Aspnetupload upldr = new aspnetupload ();
Upldr. set_uploadfolder (fpath );
Upldr. registermodelessprogressbar (this. button1); // This is the progress bar for registering button1. After you press <F5> and refresh the solution, you will see a folder named "aspnetupload_script": progressbar. on the ASPX page, change the text to Chinese.
}
Protected void button#click (Object sender, eventargs E)
{
String fpath = path. Combine (request. physicalapplicationpath, "uploadfiles ");
Uploadfilecollection files = aspnetupload. getuploadfiles ("file1 ");
Foreach (uploadfile file in files)
{
// Uploadfile file = aspnetupload. getuploadfile ("file1 ");
If (file! = NULL)
File. saveas (path. Combine (fpath, path. getfilename (file. get_filename ())));
}
}

The backend is to determine whether the "uploadfiles" folder exists. If there is no uploadfiles folder, create an "uploadfiles" folder in the root directory, and then click the button event to save the files of each upload control.

In this way, you can start to propose functions that the vs2008 upload control cannot do. If you want to upload more files at the same time, just add "<input type =" file "name =" file1 "/>. if you have any questions, please leave a message.

Bestcomy. Web. Controls. Upload. dll download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.