file_list.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 : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         if (!IsPostBack)
  17.         {
  18.             FileList.DataKeyNames = new string[] { "id" };
  19.         }
  20.     }
  21.     protected void FileList_RowCommand(object sender, GridViewCommandEventArgs e)
  22.     {
  23.         if (e.CommandName.Equals("DeleteData"))
  24.         {
  25.             string id = e.CommandArgument.ToString();
  26.             //點擊刪除按鈕
  27.             try
  28.             {
  29.                 SqlConnection conn = dbConnection.getConnection();
  30.                 conn.Open();
  31.                 SqlCommand cmd = new SqlCommand("delete from OA_REGULATION_FILE where id=" + id, conn);
  32.                 cmd.ExecuteNonQuery();
  33.                 FileList.DataBind();
  34.             }
  35.             catch (Exception ex)
  36.             {
  37.                 Response.Write(ex.Message);
  38.             }
  39.         }
  40.         if (e.CommandName.Equals("DownLoad"))
  41.         {
  42.             string id = e.CommandArgument.ToString();
  43.             //點擊下載按鈕
  44.             try
  45.             {
  46.                 SqlConnection conn = dbConnection.getConnection();
  47.                 conn.Open();
  48.                 SqlCommand cmd = new SqlCommand("select name, real_name, content_length from OA_REGULATION_FILE where id=" + id, conn);
  49.                 SqlDataReader dr = cmd.ExecuteReader();
  50.                 if (dr.Read())
  51.                 {
  52.                     this.DownLoadFile(dr["name"].ToString(), dr["real_name"].ToString(), dr["content_length"].ToString());
  53.                 }
  54.                 dr.Close();
  55.                 conn.Close();
  56.             }
  57.             catch (Exception ex)
  58.             {
  59.                 Response.Write(ex.Message);
  60.             }
  61.         }
  62.     }
  63.     protected void FileList_RowDataBound(object sender, GridViewRowEventArgs e)
  64.     {
  65.         //行高亮
  66.         if (e.Row.RowType == DataControlRowType.DataRow)
  67.         {
  68.             e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor; this.style.backgroundColor='#c8dafa';");
  69.             e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
  70.         }
  71.     }
  72.     protected void DownLoadFile(string name, string real_name, string content_length)
  73.     {
  74.         string directory = "..\oa_upload\resource_share\";
  75.         try
  76.         {
  77.             Response.Clear();
  78.             Response.ClearHeaders();
  79.             Response.Buffer = false;
  80.             Response.ContentType = "application/octet-stream";
  81.             Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(real_name, System.Text.Encoding.UTF8));
  82.             Response.AppendHeader("Content-Length", content_length);
  83.             Response.WriteFile(directory + name);
  84.             Response.Flush();
  85.             Response.End();
  86.         }
  87.         catch (Exception ex)
  88.         {
  89.             Response.Write(ex.Message);
  90.         }
  91.     }
  92. }