asp.net 2.0 file Upload (break the upload limit 4M) _ Practical Tips

Source: Internet
Author: User
Copy Code code as follows:

if (fileupload1.hasfile)
Try
{
Fileupload1.saveas ("d:\\lucenedata\\" + fileupload1.filename);
Label1.Text = "File Name:" +
FileUpload1.PostedFile.FileName + "<br>" +
FileUpload1.PostedFile.ContentLength + "kb<br>" +
"Content Type:" +
FileUpload1.PostedFile.ContentType;
}
catch (Exception ex)
{
Label1.Text = "ERROR:" + ex. Message.tostring ();
}
Else
{
Label1.Text = "You have not specified a file";
}
You can also break the default upload limit of 4MB in web.config files, such as
executiontimeout= "110"
Maxrequestlength= "11000"
Requestlengthdiskthreshold= "80"
Usefullyqualifiedredirecturl= "false"
Minfreethreads= "8"
Minlocalrequestfreethreads= "4"
apprequestqueuelimit= "5000"
Enablekerneloutputcache= "true"
Enableversionheader= "true"
Requirerootedsaveaspath= "true"
Enable= "true"
Shutdowntimeout= "90"
delaynotificationtimeout= "5"
waitchangenotification= "0"
maxwaitchangenotification= "0"
Enableheaderchecking= "true"
Sendcachecontrolheader= "true"
Apartmentthreading= "false"/>
Set the Maxrequestlenth property, here is 11000KB, or 11MB.
And for multiple file uploads, it's also simple, like an example
string filepath = "d:\\lucenedata\\";
Httpfilecollection uploadedfiles = request.files;
for (int i = 0; i < Uploadedfiles.count; i++)
{
Httppostedfile userpostedfile = uploadedfiles[i];
Try
{
if (Userpostedfile.contentlength > 0)
{
Label1.Text + = "<u>file #" + (i + 1) +
"</u><br>";
Label1.Text + = "File Content Type:" +
Userpostedfile.contenttype + "<br>";
Label1.Text + = "File Size:" +
Userpostedfile.contentlength + "kb<br>";
Label1.Text + = "File Name:" +
Userpostedfile.filename + "<br>";
Userpostedfile.saveas (filepath + "\" +
System.IO.Path.GetFileName (Userpostedfile.filename));
Label1.Text + = "Location where saved:" +
filepath + "\" +
System.IO.Path.GetFileName (Userpostedfile.filename) +
"<p>";
}
}
catch (Exception Ex)
{
Label1.Text + = "Error: <br>" + ex.message;
}
}
}

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.