Asp.net file upload and download Module

Source: Internet
Author: User

When uploading a large file, you must configure it in the web. config file and add the following nodes to the <system. web> node:

<Httpruntime usefullyqualifiedredirecturl = "true" maxrequestlength = "204800" executiontimeout = "900"/>

The maxrequestlength attribute sets the maximum size of a file that can be uploaded. The unit is kb. The default value is 4 MB. The maximum value can be set to 2 GB. If the size is exceeded, asp tutorial. net will not make any response, the setting here is 200 m.

In this way, the upload control fileupload provided by the asp.net tutorial can upload large files. If the chrome browser is used, the transfer progress will be seen in the lower left corner, but not in ie.

To display a good upload progress bar, you can use the third-party Upload Component neatupload, but the node configuration is not successful. The custom configuration section described in this article is different from the official settings, I failed to run the official code and gave up. There is also a charged aspnetupload.

Determine the file type and size on the client:

Determine the file type. The Code is as follows:

You can also use the onclientclick attribute of the button control. Note that there is a return before the client event. If the return value is false, The onclick event is not executed. The Code is as follows:

To determine the file size, activex (fso) is used to restrict different browsers and permissions. This is also true for another method.

Determine the file type and size on the server side (if the file to be uploaded is large, the size will be determined for a long time ):

The code is written to the Code, such

In web. config, you can change the type and size of the file to be uploaded at any time. The Code is as follows:

The configuration in the ettings configuration section of the apps tutorial in web. config is as follows:

Download the file using system. io:

First, obtain the list of downloaded files. The Code is as follows:

Click the button to download the selected file. The Code is as follows:

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.