Handler.ashx 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <%@ WebHandler Language="C#" Class="Handler" %>
  2. using System;
  3. using System.Web;
  4. using System.IO;
  5. public class Handler : IHttpHandler {
  6. public void ProcessRequest (HttpContext context) {
  7. context.Response.ContentType = "text/plain";
  8. string html = "";//返回数据集
  9. //新版本Grid
  10. switch (context.Request.Params["DataType"])
  11. {
  12. case "LeftMenu":
  13. string val = context.Request.Params["Value"];
  14. val = val.Replace("&amp;", "&")
  15. .Replace("&lt;", "<")
  16. .Replace("&gt;", ">")
  17. .Replace("&#039;", "'")
  18. .Replace("&quot;", "\"");
  19. html = LoadLeftMenu(val);
  20. break;
  21. case "huodong":
  22. string val2 = context.Request.Params["Value"];
  23. val2 = val2.Replace("&amp;", "&")
  24. .Replace("&lt;", "<")
  25. .Replace("&gt;", ">")
  26. .Replace("&#039;", "'")
  27. .Replace("&quot;", "\"");
  28. html = LoadHuoDong(val2);
  29. break;
  30. }
  31. context.Response.Write(html);
  32. context.Response.End();
  33. }
  34. private string LoadLeftMenu(string Value)
  35. {
  36. //生成静态页面
  37. string[] Marking = { "#Content#" };
  38. string[] Content = { Value };
  39. string HTMLURL = ConfigExportHTML(Marking, Content, 1, "handWrite.html");
  40. return HTMLURL;
  41. }
  42. private string LoadHuoDong(string Value)
  43. {
  44. //生成静态页面
  45. string[] Marking = { "#Content#" };
  46. string[] Content = { Value };
  47. string HTMLURL = ConfigExportHTML(Marking, Content, 1, "huodong.html");
  48. return HTMLURL;
  49. }
  50. #region 生成静态页面
  51. //生成静态页面
  52. public static string ConfigExportHTML(string[] Marking, string[] Content, int TemplateParamCount, string TemplateFilePath)
  53. {
  54. string Year = DateTime.Now.ToString("yyyy");
  55. string Month = DateTime.Now.ToString("yyyyMM");
  56. string RelativelyPath = "~/tpl/formbuilder/HTML/" + Year + "/" + Month + "/";//相对路径,注意更改生成的这个路径
  57. string Path = HttpContext.Current.Server.MapPath(RelativelyPath);//绝对路径
  58. //生成HTML的路径
  59. if (System.IO.Directory.Exists(Path))
  60. {
  61. //文件夹已存在
  62. }
  63. else
  64. {
  65. DirectoryInfo folder = Directory.CreateDirectory(Path);
  66. }
  67. GenerateHTML _GenerateHTML = new GenerateHTML();
  68. _GenerateHTML.TemplateParamCount = TemplateParamCount;
  69. _GenerateHTML._htmlFilePath = RelativelyPath;// 转换后的html文件所存放的路径
  70. _GenerateHTML._templateFilePath = TemplateFilePath;// 模板文件所在的路径
  71. _GenerateHTML.setAspxFileparameter(Content);
  72. _GenerateHTML.setTemplateFileparameter(Marking);
  73. string HtmlFileName = _GenerateHTML.StartConvert();//开始转换
  74. return "HTML/" + Year + "/" + Month + "/" + HtmlFileName;//返回生成文件的路径
  75. }
  76. #endregion
  77. public bool IsReusable {
  78. get {
  79. return false;
  80. }
  81. }
  82. }