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   }  
原文地址:https://www.cnblogs.com/cxy521/p/1048795.html