Asp. NET solution upload Big File Problem method _ Practical Skill

Source: Internet
Author: User

The control to upload the file is: FileUpload

ASP.net is limited to the size of the uploaded file. By default, users can only upload files of 4MB size, which can cause inconvenience to users. So if you want to upload a 40MB size file. Only configuration files can be modified

The key code is as follows

Copy Code code as follows:

protected void Btnsend_click (object sender, EventArgs e)

{

Try

{

The idea of uploading files:

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

string upfilename = Fulfilename.filename;

Get extensions for uploaded files

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 to

String FilePath =server.mappath ("./") + "File" + "//" +NEWFILENAME;

Save the file to the specified file path

FulFileName.PostedFile.SaveAs (FilePath);

Lblresult.text = "Upload success";

}

catch (Exception ex)

{

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

Lblresult.text = "Upload Failed";

}

}


Upload file key ideas: 1, first get the original name of the uploaded file, 2, and then get uploaded file extension to form a new name. 3, set the path to save to use: Server.MapPath ("./") + "File" +newfilename./represents the virtual path under the current page, file indicates that the file folder in the current page must first create this folder 4, Saves the file to the specified file path. The SaveAs () method of the Postfile using the FileUpload control

The implementation of uploading large files requires modifying the web.config file.

<system.web>

</system.web>

Key set to maxRequestLength this attribute represents 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: 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.