DownloadFile.aspx.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. namespace iNethinkCMS.Web.UserCenter
  8. {
  9. public partial class DownloadFile : System.Web.UI.Page
  10. {
  11. protected void Page_Load(object sender, EventArgs e)
  12. {
  13. if (!IsPostBack)
  14. {
  15. string SysLoginUserName = iNethinkCMS.Command.Command_Session.Get("admin_username");
  16. if (String.IsNullOrEmpty(SysLoginUserName))
  17. {
  18. Response.Write("<font color='#ff0000'>对不起,需要登录后才能下载。</font>");
  19. }
  20. else
  21. {
  22. int id = 0;
  23. if (Request.QueryString["id"] != null && Request.QueryString["id"].ToString().Length > 1)
  24. {
  25. try
  26. {
  27. id = Convert.ToInt32(Request.QueryString["id"].ToString());
  28. }
  29. catch { }
  30. }
  31. if (Request.QueryString["File"] != null && Request.QueryString["File"].ToString().Length > 1)
  32. {
  33. string downloadFileName = Request.QueryString["File"].ToString();
  34. if (downloadFileName.ToLower().StartsWith("http://") || downloadFileName.ToLower().StartsWith("https://"))
  35. {
  36. if (id > 0)
  37. {
  38. Response.Write("<iframe style=\"display:none;\" src=\"/plugs/count/count.aspx?id=" + id.ToString() + "\"></iframe>");
  39. }
  40. iNethinkCMS.Command.MessageBox.ResponseScript(this, "location.href='" + downloadFileName+ "'");
  41. // Response.Write("<script type=\"text/javascript\"></script>");
  42. }
  43. else
  44. {
  45. try
  46. {
  47. string iframeSrc = "/upload/day_" + downloadFileName;
  48. string downloadFilePath = Server.MapPath(iframeSrc);
  49. if (!System.IO.File.Exists(downloadFilePath))
  50. {
  51. iframeSrc = "/upload/" + downloadFileName;
  52. downloadFilePath = Server.MapPath(iframeSrc);
  53. if (!System.IO.File.Exists(downloadFilePath))
  54. {
  55. iframeSrc = "/" + downloadFileName;
  56. downloadFilePath = Server.MapPath(iframeSrc);
  57. }
  58. }
  59. if (System.IO.File.Exists(downloadFilePath))
  60. {
  61. Response.Write("<iframe style=\"display:none;\" src=\"" + iframeSrc + "\"></iframe>");
  62. if (id > 0)
  63. {
  64. Response.Write("<iframe style=\"display:none;\" src=\"/plugs/count/count.aspx?id=" + id.ToString() + "\"></iframe>");
  65. }
  66. }
  67. else
  68. {
  69. Response.Write("<font color='#ff0000'>请求下载的文件不存在或已被删除...</font>");
  70. }
  71. }
  72. catch(Exception ex) {
  73. Response.Write("<font color='#ff0000'>请求下载的文件路径不正确,"+ex.Message+"</font>");
  74. }
  75. }
  76. }
  77. else
  78. {
  79. Response.Write("<font color='#ff0000'>请求下载参数不正确。</font>");
  80. }
  81. }
  82. }
  83. else {
  84. Response.Write("<font color='#ff0000'>请求已过期,请重新请求...</font>");
  85. }
  86. }
  87. }
  88. }