zoukankan      html  css  js  c++  java
  • 第三方Girdview中文件下载的方法,以及js显示图片

     

     /// <summary>  

    /// 文件下载事件 

     /// </summary>   

       /// <param name="sender"></param>

            /// <param name="e"></param>   

          protected void Grid_OnCopyInsertClick(object sender, EventArgs e)         {        

         LinkButton LBut = sender as LinkButton;          

       string sellContractScanId = LBut.CommandName;       

          string url = "";         

        string name = "";          

       foreach (DataRow dr in griViewTable.Rows)             {             

        if (dr["序号"].ToString().Equals(sellContractScanId))                 {           

              url = dr["路径"].ToString();                    

    name = dr["文件名称"].ToString();                  

       break;            

         }             }       

          if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(url)))             {       

              Response.Redirect("UserInfoScanDownload.aspx?FilePath=" + url + "&FileName=" + name);         

        }        

         else        

         {                 bp.Alert("文件不存在!");

                }

     

     

     

     

      BasePage bp = null;      

       protected void Page_Load(object sender, EventArgs e)         {     

            if (Request["FilePath"] == null)              

       return;          

       if (Request["FileName"] == null)           

          return;

                string fileRpath = Request["FilePath"].ToString();        

         string fileName = Request["FileName"].ToString();

                if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(fileRpath)))             {

                    Response.ClearHeaders();          

           Response.Clear();              

       Response.Expires = 0;                

    Response.Buffer = true;              

       Response.AddHeader("Accept-Language", "zh-tw");           

          string name = System.IO.Path.GetFileName(fileRpath);     

                System.IO.FileStream files = new FileStream(HttpContext.Current.Server.MapPath(fileRpath), FileMode.Open, FileAccess.Read, FileShare.Read);                 byte[] byteFile = null;           

          if (files.Length == 0)                 {           

              byteFile = new byte[1];               

      }         

            else         

            {                    

    byteFile = new byte[files.Length];      

               }                

    files.Read(byteFile, 0, (int)byteFile.Length);     

                files.Close();

                    Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));                 Response.ContentType = "application/octet-stream;charset=gbk";         

            Response.BinaryWrite(byteFile);          

           Response.End();        

         }      

       }

  • 相关阅读:
    [LeetCode] 19. Remove Nth Node From End of List 移除链表倒数第N个节点
    [LeetCode] 27. Remove Element 移除元素
    [LeetCode] 240. Search a 2D Matrix II 搜索一个二维矩阵 II
    [LeetCode] 74. Search a 2D Matrix 搜索一个二维矩阵
    [LeetCode] 452. Minimum Number of Arrows to Burst Balloons 最少箭数爆气球
    [LeetCode] 312. Burst Balloons 爆气球
    [LeetCode] 257. Binary Tree Paths 二叉树路径
    [LeetCode] 24. Swap Nodes in Pairs 成对交换节点
    [LeetCode] 680. Valid Palindrome II 验证回文字符串 II
    [LeetCode] 234. Palindrome Linked List 回文链表
  • 原文地址:https://www.cnblogs.com/520lw/p/3983550.html
Copyright © 2011-2022 走看看