fork download
  1. public partial class WebForm1 : System.Web.UI.Page
  2. {
  3. const string defaultPath = @"C:\files";
  4. private static string fileName = String.Empty;
  5.  
  6. protected void Page_Load(object sender, EventArgs e)
  7. {
  8. this.AsyncFileUpload.UploadedComplete += new EventHandler<AjaxControlToolkit.AsyncFileUploadEventArgs>(AsyncFileUpload_UploadedComplete);
  9.  
  10. if (Page.IsPostBack)
  11. {
  12. CheckStatus();
  13. }
  14. }
  15.  
  16. void AsyncFileUpload_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
  17. {
  18. switch (e.State)
  19. {
  20. case AjaxControlToolkit.AsyncFileUploadState.Success:
  21. SaveUploadedFile(ref e);
  22. break;
  23. case AjaxControlToolkit.AsyncFileUploadState.Failed:
  24. SetErrorOnLabel();
  25. break;
  26. case AjaxControlToolkit.AsyncFileUploadState.Unknown:
  27. SetErrorOnLabel();
  28. break;
  29. }
  30. }
  31.  
  32. void SaveUploadedFile(ref AjaxControlToolkit.AsyncFileUploadEventArgs e)
  33. {
  34. fileName = Guid.NewGuid().ToString() + e.FileName;
  35. this.AsyncFileUpload.SaveAs(defaultPath + fileName);
  36. }
  37.  
  38. void SetErrorOnLabel()
  39. {
  40. this.mainLabel.Text = "Error";
  41. }
  42.  
  43. void CheckStatus()
  44. {
  45. bool doesExist = System.IO.File.Exists(defaultPath + fileName);
  46. if (doesExist) this.mainLabel.Text = fileName + @" has been uploaded to the " + defaultPath + fileName;
  47. else this.mainLabel.Text = "Error";
  48. }
  49. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty