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;
}
}
}