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