fileUpload.aspx.cs 4.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. up_filenm = Server.MapPath(string.Format(@".\UPLOAD\{0}", up_filenm));
  21. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload: {0}", up_filenm));
  22. foreach (string f in Request.Files.AllKeys)
  23. {
  24. HttpPostedFile file = Request.Files[f];
  25. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload Impersonate START workemr"));
  26. //// 윈도우 계정으로 Impersonate
  27. ClipSoft.Utility.ImpersonationUtility util = new ClipSoft.Utility.ImpersonationUtility();
  28. util.ImpersonationStart(string.Empty, "workemr", "workemr");
  29. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload Impersonate END"));
  30. // 디렉토리 존재여부 체크
  31. DirectoryInfo di = new DirectoryInfo(up_filenm.Substring(0, up_filenm.LastIndexOf("\\") + 1));
  32. if (di.Exists == false)
  33. {
  34. di.Create();
  35. }
  36. // 파일 저장
  37. file.SaveAs(up_filenm);
  38. // Impersonate 종료
  39. util.ImpersonationEnd();
  40. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload Impersonate CLOSE"));
  41. /*
  42. //임시 디렉토리에 복사
  43. string tempFile = Server.MapPath("./DataTempImage/") + file.FileName;
  44. file.SaveAs(tempFile);
  45. File.Copy(tempFile, up_filenm, true);
  46. */
  47. }
  48. }
  49. else if (fp != null)
  50. {
  51. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("Request.QueryString"));
  52. fp = Request.Files["up_path"];
  53. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("ANDROID File up_path"));
  54. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(fp.FileName);
  55. string up_filenm = fp.FileName;
  56. //up_filenm = Server.MapPath(string.Format("./{0}", up_filenm));
  57. up_filenm = Server.MapPath(string.Format(@".\UPLOAD\{0}", up_filenm));
  58. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload: {0}", up_filenm));
  59. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload Impersonate START workemr"));
  60. //// 윈도우 계정으로 Impersonate
  61. ClipSoft.Utility.ImpersonationUtility util = new ClipSoft.Utility.ImpersonationUtility();
  62. util.ImpersonationStart(string.Empty, "workemr", "workemr");
  63. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload Impersonate END"));
  64. // 디렉토리 존재여부 체크
  65. DirectoryInfo di = new DirectoryInfo(up_filenm.Substring(0, up_filenm.LastIndexOf("\\") + 1));
  66. if (di.Exists == false)
  67. {
  68. di.Create();
  69. }
  70. // 파일 저장
  71. fp.SaveAs(up_filenm);
  72. // Impersonate 종료
  73. util.ImpersonationEnd();
  74. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload Impersonate CLOSE"));
  75. }
  76. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm File Upload End"));
  77. }
  78. catch (Exception ex)
  79. {
  80. CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("CLIP.eForm error: {0}", ex.Message));
  81. throw ex;
  82. }
  83. }
  84. }