PictureUpload.ashx.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Web;
  6. namespace WWPipeLine.MapWebTools.Tools
  7. {
  8. /// <summary>
  9. /// PictureUpload 的摘要说明
  10. /// </summary>
  11. public class PictureUpload : IHttpHandler
  12. {
  13. private static string imgUploadDir = System.Configuration.ConfigurationManager.ConnectionStrings["imgUploadDir"].ConnectionString;
  14. private static string GISversion = System.Configuration.ConfigurationManager.ConnectionStrings["GISversion"].ConnectionString;
  15. public void ProcessRequest(HttpContext context)
  16. {
  17. //context.Response.ContentType = "text/plain";
  18. //context.Response.Write("Hello World");
  19. string action = context.Request.QueryString["action"];
  20. switch (action)
  21. {
  22. case "UpLoadFile":
  23. UpLoadFile(context);
  24. break;
  25. case "getGISversion":
  26. {
  27. context.Response.Write(GISversion);
  28. context.Response.End();
  29. }
  30. break;
  31. default:
  32. UpLoadFile(context);
  33. break;
  34. }
  35. }
  36. private void UpLoadFile(HttpContext context)
  37. {
  38. try
  39. {
  40. string fileName = context.Request.QueryString["name"];
  41. if (string.IsNullOrEmpty(fileName))
  42. {
  43. context.Response.Write(""); context.Response.End(); return;
  44. }
  45. string imgMapPath = context.Server.MapPath(imgUploadDir);
  46. if (!Directory.Exists(imgMapPath))
  47. Directory.CreateDirectory(imgMapPath);
  48. foreach (string f in context.Request.Files.AllKeys)
  49. {
  50. HttpPostedFile httpPostedFile = context.Request.Files[f];
  51. httpPostedFile.SaveAs(imgMapPath + fileName);
  52. }
  53. context.Response.Write(imgUploadDir + fileName);
  54. }
  55. catch (Exception ex)
  56. {
  57. context.Response.Write("");
  58. }
  59. finally
  60. {
  61. context.Response.End();
  62. }
  63. }
  64. public bool IsReusable
  65. {
  66. get
  67. {
  68. return false;
  69. }
  70. }
  71. }
  72. }