Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
saveFile = Path.Combine (savePath, FileUpload1.FileName) FileUpload1.SaveAs (saveFile); / / Hiển thị trạng thái của sự thành công StatusLabel.Text = "file của bạn đã được tải lên thành công.";} catch (Exception exUpload) {/ / hiển thị trạng thái lỗi StatusLabel.Text exUpload.Message;}} else {/ / có thể tập tin không phải là lựa chọn / trạng thái / Hiển thị của sự thất bại StatusLabel.Text = "Bạn không chỉ định một tập tin để tải lên.";} . | Chapter 8 saveFile Path.Combine savePath FileUploadl.FileName FileUploadl.SaveAs saveFile Displays status of success StatusLabel.Text Your file was uploaded successfully. catch Exception exUpload display status of error StatusLabel.Text exUpload.Message else probably file was not selected Display status of failure StatusLabel.Text You did not specify a file to upload. In the following Try It Out you give users a way to add pictures to the gallery. Try It Out Uploading Files Basic 1. Using VWD create a new page named GalleryUpload.aspx using the Web Form template. As you have with most pages up to this point use the site.master as the Master page use Visual C and enable the option to place the code on a separate page. 2. In Design View add a FileUpload control from the Toolbox and a Label control that will have an ID of FileUploadReport with an empty text property. Also add a button control with the text property set to Upload . 3. Double-click the button to go to its code. Add the following shaded code to the Sub using System using System.IO using . public partial class GalleryUpload System.Web.UI.Page protected void Buttonl_Click object sender EventArgs e string ImagesFolder Matchimages string savePath string saveFile if FileUploadl.HasFile try perform the upload savePath Path.Combine Request.PhysicalApplicationPath ImagesFolder saveFile Path.Combine savePath FileUploadl.FileName FileUploadl.SaveAs saveFile Displays status of success FileUploadReport.Text Your file was uploaded successfully. catch Exception exUpload 276 Writing Data display status of error FileUploadReport.Text exUpload.Message else probably file was not selected Display status of failure FileUploadReport.Text You did not specify a file to upload. 4. Save the page and view it in your browser see Figure 8-11 . You probably won t have pictures of the hapless Wrox United tumblers but you can try uploading any jpeg or gif you have on your hard drive. Figure 8-11 How It Works The FileUpload control .