Use of the upload control and the upload Control
Protected void btn_Upload_Click (object sender, EventArgs e) {string serverPath = Server. MapPath ("Upload"); if (! System. IO. directory. exists (serverPath) // checks whether the file directory Exists {System. IO. directory. createDirectory (serverPath); // if the file directory does not exist, create a file directory} if (file_upload.HasFile) // determine whether the control {int fileSize = this. file_upload.PostedFile.ContentLength/1024/1024; // obtain the size of the uploaded file if (fileSize> 8) // if the size of the uploaded file is greater than 8 Mb {Page. clientScript. registerStartupScript (this. getType (), "", "alert ('only files smaller than 8 megabytes allowed to be uploaded ')", true); return;} else {file_upload. SaveAs (serverPath + "\" + file_upload.FileName); // save the file to the specified directory of the server Page. clientScript. registerStartupScript (this. getType (), "", "alert ('file uploaded successfully !! ') ", True) ;}} else {Page. clientScript. registerStartupScript (this. getType (), "", "alert ('select the file to upload ')", true); return ;}}