file_list.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:3k
源码类别:
OA系统
开发平台:
ASP/ASPX
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Data.SqlClient;
- public partial class web_regulation_file_list : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- FileList.DataKeyNames = new string[] { "id" };
- }
- }
- protected void FileList_RowCommand(object sender, GridViewCommandEventArgs e)
- {
- if (e.CommandName.Equals("DeleteData"))
- {
- string id = e.CommandArgument.ToString();
- //點擊刪除按鈕
- try
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("delete from OA_REGULATION_FILE where id=" + id, conn);
- cmd.ExecuteNonQuery();
- FileList.DataBind();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- if (e.CommandName.Equals("DownLoad"))
- {
- string id = e.CommandArgument.ToString();
- //點擊下載按鈕
- try
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select name, real_name, content_length from OA_REGULATION_FILE where id=" + id, conn);
- SqlDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- this.DownLoadFile(dr["name"].ToString(), dr["real_name"].ToString(), dr["content_length"].ToString());
- }
- dr.Close();
- conn.Close();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- }
- protected void FileList_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- //行高亮
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor; this.style.backgroundColor='#c8dafa';");
- e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
- }
- }
- protected void DownLoadFile(string name, string real_name, string content_length)
- {
- string directory = "..\oa_upload\resource_share\";
- try
- {
- Response.Clear();
- Response.ClearHeaders();
- Response.Buffer = false;
- Response.ContentType = "application/octet-stream";
- Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(real_name, System.Text.Encoding.UTF8));
- Response.AppendHeader("Content-Length", content_length);
- Response.WriteFile(directory + name);
- Response.Flush();
- Response.End();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- }