CopyCode The Code is as follows: if (fileupload1.hasfile)
Try
{
Fileupload1.saveas ("D: \ javasedata \" + 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 4 MB in the web. config file, for example
<Httpruntime
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 attribute, Which is 11000kb, that is, 11 Mb.
It is also very easy to upload multiple files, for example, 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;
}
}
}