file_list_view.aspx.cs
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:3k
源码类别:

OA系统

开发平台:

ASP/ASPX

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12. public partial class web_regulation_file_list_view : System.Web.UI.Page
  13. {
  14.     
  15.     protected void Page_Load(object sender, EventArgs e)
  16.     {
  17.         
  18.         if (!IsPostBack)
  19.         { 
  20.             FileList.DataKeyNames = new string[] { "id" };
  21.             Session["dir_id"] = Request.QueryString["dir_id"];
  22.         }
  23.     }
  24.     protected void FileList_RowCommand(object sender, GridViewCommandEventArgs e)
  25.     {
  26.         if (e.CommandName.Equals("DownLoad"))
  27.         {
  28.             string id = e.CommandArgument.ToString();
  29.             //點擊下載按鈕
  30.             try
  31.             {
  32.                 
  33.                 SqlConnection conn = dbConnection.getConnection();
  34.                 conn.Open();
  35.                 SqlCommand cmd = new SqlCommand("select name, real_name, content_length from OA_REGULATION_FILE where id=" + id, conn);
  36.                 SqlDataReader dr = cmd.ExecuteReader();
  37.                 if (dr.Read())
  38.                 {
  39.                     this.DownLoadFile(dr["name"].ToString(), dr["real_name"].ToString(), dr["content_length"].ToString());
  40.                 }
  41.                 dr.Close();
  42.                 conn.Close();
  43.             }
  44.             catch (Exception ex)
  45.             {
  46.                 Response.Write(ex.Message);
  47.             }
  48.         }
  49.     }
  50.     protected void FileList_RowDataBound(object sender, GridViewRowEventArgs e)
  51.     {
  52.         //行高亮
  53.         if (e.Row.RowType == DataControlRowType.DataRow)
  54.         {
  55.             e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor; this.style.backgroundColor='#c8dafa';");
  56.             e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
  57.         }
  58.     }
  59.     protected void DownLoadFile(string name, string real_name, string content_length)
  60.     {
  61.         
  62.         try
  63.         {
  64.            
  65.             string directory = "..\oa_upload\resource_share\";       
  66.             Response.Clear();
  67.             Response.ClearHeaders();
  68.             Response.Buffer = false;
  69.             Response.ContentType = "application/octet-stream";
  70.             Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(real_name, System.Text.Encoding.UTF8));
  71.             Response.AppendHeader("Content-Length", content_length);
  72.             Response.WriteFile(directory+name);
  73.             Response.Flush();
  74.             Response.End();
  75.         }
  76.         catch (Exception ex)
  77.         {
  78.             Response.Write(ex.Message);
  79.         }
  80.     }
  81. }