asp.net| Control | upload | Upload Control
Try the upload control of ASP.net 2.0, it is very convenient.
Share the code as follows:
protected void Button1_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 = "file is greater than 50k and cannot be uploaded";
Return
}
#endregion
Determine if the saved folder exists #region determine if the saved folder exists
String struppath = @ "upfile\" + System.DateTime.Now.ToShortDateString ();//+@ "\";
Create a folder when the folder does not exist
if (! System.IO.Directory.Exists (Server.MapPath (Struppath))
{
System.IO.Directory.CreateDirectory (Server.MapPath (Struppath));
}
String strURL = Server.MapPath (Struppath + @ "\" + this. Fileupload1.filename);
#endregion
Uploading files
This. Fileupload1.saveas (strURL);
This. Label1.Text = "File upload success";
}
catch (System.Exception ex)
{
This. Label1.Text = "File upload failed:" + ex. message;
}
}