首页 > 代码库 > 第三方Girdview中文件下载的方法,以及js显示图片

第三方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();        

     }      

   }

第三方Girdview中文件下载的方法,以及js显示图片