fileUpload.aspx.cs 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Web;
  3. using System.IO;
  4. public partial class fileUpload : System.Web.UI.Page
  5. {
  6. protected void Page_Load(object sender, EventArgs e)
  7. {
  8. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload Start"));
  9. try
  10. {
  11. HttpPostedFile fp = Request.Files["up_path"];
  12. if (Request.QueryString != null && Request.QueryString.Count > 0)
  13. {
  14. //O:\fnuImage\201607\19\100501967.jpg
  15. //Image3\fnuimage\201607\19\100501967.jpg
  16. //string up_filenm = Request.QueryString["up_path"].ToString();
  17. string up_filenm = Request.QueryString["up_path"].ToString();
  18. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload: {0}", up_filenm));
  19. up_filenm = Server.MapPath(string.Format("./{0}", up_filenm));
  20. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload: {0}", up_filenm));
  21. foreach (string f in Request.Files.AllKeys)
  22. {
  23. HttpPostedFile file = Request.Files[f];
  24. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload Impersonate START workemr"));
  25. //// 윈도우 계정으로 Impersonate
  26. ClipSoft.Utility.ImpersonationUtility util = new ClipSoft.Utility.ImpersonationUtility();
  27. util.ImpersonationStart(string.Empty, "workemr", "workemr");
  28. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload Impersonate END"));
  29. // 디렉토리 존재여부 체크
  30. DirectoryInfo di = new DirectoryInfo(up_filenm.Substring(0, up_filenm.LastIndexOf("\\") + 1));
  31. if (di.Exists == false)
  32. {
  33. di.Create();
  34. }
  35. // 파일 저장
  36. file.SaveAs(up_filenm);
  37. // Impersonate 종료
  38. util.ImpersonationEnd();
  39. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload Impersonate CLOSE"));
  40. /*
  41. //임시 디렉토리에 복사
  42. string tempFile = Server.MapPath("./DataTempImage/") + file.FileName;
  43. file.SaveAs(tempFile);
  44. File.Copy(tempFile, up_filenm, true);
  45. */
  46. }
  47. }
  48. else if (fp != null)
  49. {
  50. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("Request.QueryString"));
  51. fp = Request.Files["up_path"];
  52. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("ANDROID File up_path"));
  53. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(fp.FileName);
  54. string up_filenm = fp.FileName;
  55. up_filenm = Server.MapPath(string.Format("./{0}", up_filenm));
  56. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload: {0}", up_filenm));
  57. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload Impersonate START workemr"));
  58. //// 윈도우 계정으로 Impersonate
  59. ClipSoft.Utility.ImpersonationUtility util = new ClipSoft.Utility.ImpersonationUtility();
  60. util.ImpersonationStart(string.Empty, "workemr", "workemr");
  61. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload Impersonate END"));
  62. // 디렉토리 존재여부 체크
  63. DirectoryInfo di = new DirectoryInfo(up_filenm.Substring(0, up_filenm.LastIndexOf("\\") + 1));
  64. if (di.Exists == false)
  65. {
  66. di.Create();
  67. }
  68. // 파일 저장
  69. fp.SaveAs(up_filenm);
  70. // Impersonate 종료
  71. util.ImpersonationEnd();
  72. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload Impersonate CLOSE"));
  73. }
  74. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload End"));
  75. }
  76. catch (Exception ex)
  77. {
  78. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm error: {0}", ex.Message));
  79. throw ex;
  80. }
  81. }
  82. }