• Excel下载控制


     1 private   static   bool   DownFile(System.Web.HttpResponse   Response,string   fileName,string   fullPath)  
     2   {  
     3   try  
     4   {  
     5   Response.ContentType   =   "application/octet-stream";  
     6       
     7   Response.AppendHeader("Content-Disposition","attachment;filename="   +   
     8   System.Web.HttpUtility.UrlEncode(fileName,System.Text.Encoding.UTF8)   +   ";charset=GB2312");   
     9   System.IO.FileStream   fs=   System.IO.File.OpenRead(fullPath);  
    10   long   fLen=fs.Length;  
    11   int   size=102400;//每100K同时下载数据   
    12   byte[]   readData   =   new   byte[size];//指定缓冲区的大小   
    13   if(size>fLen)size=Convert.ToInt32(fLen);  
    14   long   fPos=0;  
    15   bool   isEnd=false;  
    16   while   (!isEnd)   
    17   {   
    18   if((fPos+size)>fLen)  
    19   {  
    20   size=Convert.ToInt32(fLen-fPos);  
    21   readData   =   new   byte[size];  
    22   isEnd=true;  
    23   }  
    24   fs.Read(readData,   0,   size);//读入一个压缩块   
    25   Response.BinaryWrite(readData);  
    26   fPos+=size;  
    27   }   
    28   fs.Close();   
    29   System.IO.File.Delete(fullPath);  
    30   return   true;  
    31   }  
    32   catch  
    33   {  
    34   return   false;  
    35   }  
    36   }  
  • 相关阅读:
    哈哈,原来这叫做“松鼠症”……并谈谈我建议的学习方法
    入坑IT十年(二)技术以外
    入坑IT都快十年了
    也来谈谈IT培训
    技术,是不是越新越好?
    十年之后再看“面向对象”
    话说,你这样根本就不应该去“创业型”公司
    我为什么不做外包
    NetTopologySuite Geometry&WKT&WKB&GeoJSON互转
    wpf 打印图片
  • 原文地址:https://www.cnblogs.com/cxy521/p/1048795.html
Copyright © 2020-2023  润新知