洛阳中航光电项目,为12年项目,此处使用反编译工具恢复源码,恢复为.netframe4.0版本,但仍需使用ie8访问; 数据库使用oracle,现再192.168.8.3服务器,访问账户scott,密码800100

UpLoadFiles.cs 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. using System.IO;
  3. using System.Web;
  4. using System.Web.UI.HtmlControls;
  5. namespace Common
  6. {
  7. public class UpLoadFiles
  8. {
  9. public class upfile
  10. {
  11. private string path = null;
  12. private string fileType = null;
  13. private int sizes = 0;
  14. public string Path
  15. {
  16. set
  17. {
  18. this.path = "/" + value + "/";
  19. }
  20. }
  21. public int Sizes
  22. {
  23. set
  24. {
  25. this.sizes = value * 1024;
  26. }
  27. }
  28. public string FileType
  29. {
  30. set
  31. {
  32. this.fileType = value;
  33. }
  34. }
  35. public upfile()
  36. {
  37. this.path = "";
  38. this.fileType = "";
  39. this.sizes = 409600000;
  40. }
  41. public string fileSaveAs(HtmlInputFile name, string dept)
  42. {
  43. string filePath = null;
  44. string result;
  45. try
  46. {
  47. string monthFiles = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString();
  48. string mappathinfo = HttpContext.Current.Request.PhysicalApplicationPath + this.path;
  49. if (!Directory.Exists(mappathinfo + dept + "\\" + monthFiles.Trim()))
  50. {
  51. Directory.CreateDirectory(mappathinfo + dept + "\\" + monthFiles.Trim());
  52. }
  53. string upLoadPath = mappathinfo + dept + "\\" + monthFiles.Trim();
  54. string sourcePath = name.Value.Trim();
  55. if (sourcePath == "" || sourcePath == null)
  56. {
  57. this.message("您没有上传数据!");
  58. result = null;
  59. return result;
  60. }
  61. int start = sourcePath.LastIndexOf("\\") + 1;
  62. int end = sourcePath.Length;
  63. string filename = DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + sourcePath.Substring(start, end - start);
  64. filePath = upLoadPath + "\\" + filename;
  65. FileInfo _file = new FileInfo(filePath);
  66. if (_file.Exists)
  67. {
  68. this.message("该文件已存在,请查验或修改文件名称");
  69. result = null;
  70. return result;
  71. }
  72. string tFileType = sourcePath.Substring(sourcePath.LastIndexOf(".") + 1);
  73. long strLen = (long)name.PostedFile.ContentLength;
  74. string[] temp = this.fileType.Split(new char[]
  75. {
  76. '|'
  77. });
  78. bool flag = false;
  79. if (strLen >= (long)this.sizes)
  80. {
  81. this.message("上传的数据不能大于" + this.sizes + "KB");
  82. result = null;
  83. return result;
  84. }
  85. string[] array = temp;
  86. for (int i = 0; i < array.Length; i++)
  87. {
  88. string data = array[i];
  89. if (data == tFileType)
  90. {
  91. flag = true;
  92. break;
  93. }
  94. }
  95. if (!flag)
  96. {
  97. this.message("目前本系统支持的格式为:" + this.fileType);
  98. result = null;
  99. return result;
  100. }
  101. name.PostedFile.SaveAs(filePath);
  102. filePath = monthFiles + "/" + filename;
  103. }
  104. catch
  105. {
  106. this.message("出现未知错误!");
  107. result = null;
  108. return result;
  109. }
  110. result = filePath;
  111. return result;
  112. }
  113. private void message(string msg, string url)
  114. {
  115. HttpContext.Current.Response.Write(string.Concat(new string[]
  116. {
  117. "<script language=javascript>alert('",
  118. msg,
  119. "');window.location='",
  120. url,
  121. "'</script>"
  122. }));
  123. }
  124. private void message(string msg)
  125. {
  126. HttpContext.Current.Response.Write("<script language=javascript>alert('" + msg + "');</script>");
  127. }
  128. }
  129. }
  130. }