码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2014-09-20 21:31:19      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   os   ar   for   文件   2014   

bubuko.com,布布扣
 

 /// <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显示图片

标签:style   blog   http   io   os   ar   for   文件   2014   

原文地址:http://www.cnblogs.com/520lw/p/3983550.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!