ASP. NET solution for uploading large files

Source: Internet
Author: User

The file upload control is: FileUpload.

Asp. Net has a limit on the size of the uploaded files. By default, users can only upload 4 MB files, which may cause inconvenience to users. Therefore, if you want to upload a 40 MB file. Only configuration files can be modified

The key code is as follows:

Copy codeThe Code is as follows: protected void btnSend_Click (object sender, EventArgs e)




// Idea of uploading files:

// Get the name of the uploaded file, which is a full path address

String upFileName = fulFileName. FileName;

// Obtain the extension of the uploaded file

String lastName = upFileName. Substring (upFileName. LastIndexOf ("."));

// Get the new file name

String newFileName = txtFileName. Text + lastName;

// Set the path of the file to be saved

String FilePath = Server. MapPath ("./") + "File" + "//" + newFileName;

// Save the file to the specified file path

FulFileName. PostedFile. SaveAs (FilePath );

LblResult. Text = "uploaded successfully ";


Catch (Exception ex)


Response. Write (ex. Message. ToString ());

LblResult. Text = "Upload Failed ";



Key train of thought: 1. Get the original name of the uploaded file first, 2. Get the extension of the uploaded file to form a new name. 3. Set the path to be saved to use: Server. mapPath (". /") +" File "+ newFileName. /indicates the virtual path on the current page. File indicates that the File folder on the current page must be created first. 4. Save the File to the specified File path. Use the SaveAs () method of the PostFile of the FileUpload Control

To upload large files, you must modify the Web. config file.

<System. web>

<HttpRuntime maxRequestLength = "40960" executionTimeOut = "6000"/>

</System. web>

Key setting: maxRequestLength. This attribute indicates the maximum number of bytes uploaded.

Related Article

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: 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.