I tried the upload control of Asp.net 2.0, which is quite convenient.
ShareCodeAs follows:
Protected Void Button#click ( Object Sender, eventargs E)
{
Try
{
Determine File Size # Region Determine File Size
Int Intfilelength = This . Fileupload1.postedfile. contentlength;
If (Intfilelength > 50000 )
{
This. Label1.text= "Files larger than 50 kb cannot be uploaded";
Return;
}
# Endregion
Determine whether the saved folder exists # Region Determine whether the saved folder exists
String Struppath = @" Upfile \ " + System. datetime. Now. tow.datestring (); // + @"\";
// When the folder does not exist, create a folder
If ( ! System. Io. Directory. exists (server. mappath (struppath )))
{
System. Io. Directory. createdirectory (server. mappath (struppath ));
}
String Strurl = Server. mappath (struppath + @" \ " + This . Fileupload1.filename );
# Endregion
// Upload files
This . Fileupload1.saveas (strurl );
This . Label1.text = " File Uploaded " ;
}
Catch (System. Exception ex)
{
This. Label1.text= "File Upload Failed:" +Ex. message;
}
}
Example project:/files/heekui/webupload.rar