Exemplo n.º 1
0
    protected void GridFileView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Download"))
        {
            GridViewRow row       = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
            HiddenField HiddenKey = (HiddenField)row.Cells[0].FindControl("HiddenKey");
            string      pname     = e.CommandArgument.ToString();

            string fileName      = Path.GetFileNameWithoutExtension(pname);
            string fileExtension = Path.GetExtension(pname);

            //Build the File Path for the original (input) and the decrypted (output) file
            string input  = Server.MapPath("~/temp/") + fileName + fileExtension;
            string output = Server.MapPath("~/temp/") + fileName + "_dec" + fileExtension;

            if ((System.IO.File.Exists(output)))
            {
            }
            else
            {
                this.Decrypt(input, output, HiddenKey.Value);
            }



            Response.ContentType = "text/txt";
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + pname);
            Response.TransmitFile(output);
            Response.End();


            if (output != null || output != string.Empty)
            {
                if ((System.IO.File.Exists(output)))
                {
                    System.IO.File.Delete(output);
                }
            }
        }
        if (e.CommandName.Equals("Delete"))
        {
            if (SQlDataAccess.GetInstance().ExecuteCommandSql("delete dbo.Files where Files_Id = " + Convert.ToInt32(e.CommandArgument)))
            {
                Utils.ShowAlertMessage("File Deleted");
                LoadGrid();
            }
        }
    }
Exemplo n.º 2
0
        public Form1()
        {
            InitializeComponent();
            // Database setup
            string connectionString = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString;

            TableName = ConfigurationManager.AppSettings.Get("table_name");
            try
            {
                _db = new SQlDataAccess(connectionString);
            }
            catch (SqlException e)
            {
                MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK);
            }


            // Setup
            SetupLayout();
            SetupCheckboxes();
        }