fileUpload.aspx.cs 4.1 KB

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