private void cmdUpload_Click(object sender, System.EventArgs e) { if (( File1.PostedFile != null) && (File1.PostedFile.ContentLength > 0)) { //determine file name string sFileName = System.IO.Path.GetFileName(File1.PostedFile.FileName); try { if (File1.PostedFile.ContentLength <= lMaxFileSize) { //Save File on disk File1.PostedFile.SaveAs(sFileDir + sFileName); lblMessage.Visible=true; lblMessage.Text="File: " + sFileDir + sFileName + " Uploaded Successfully"; } else //reject file { lblMessage.Visible=true; lblMessage.Text="File Size if Over the Limit of " + lMaxFileSize ; } } catch(Exception)//in case of an error { lblMessage.Visible = true; lblMessage.Text="An Error Occured. Please Try Again!"; DeleteFile(sFileDir + sFileName); } } } |