asp.net 2.0 use of upload controls

Source: Internet
Author: User
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;
}
}



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.