Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1448238
  • 博文数量: 254
  • 博客积分: 8696
  • 博客等级: 中将
  • 技术积分: 2961
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-03 16:46
文章分类

全部博文(254)

文章存档

2015年(4)

2014年(18)

2013年(16)

2012年(8)

2011年(25)

2010年(2)

2009年(74)

2008年(107)

分类: Java

2008-07-14 11:10:38

public   static   void   FileDownload(string   FullFileName)  
                  {  
                          //FileInfo   Driver_Path   =   new   FileInfo(FullFileName);    
                          string   Driver_Path=HttpContext.Current.Server.MapPath(".")+"\\DownLoad\\"+FullFileName;  
                          if   (!File.Exists(Driver_Path))  
                          {  
                                  HttpContext.Current.Response.Write("");  
                                  return;  
                          }  
   
   
                          try  
                          {  
                                  FileInfo   file1   =   new   FileInfo(Driver_Path);  
                                  HttpContext.Current.Response.Clear();  
                                  HttpContext.Current.Response.ClearHeaders();  
                                  HttpContext.Current.Response.ClearContent();  
                                  HttpContext.Current.Response.Buffer   =   false;  
                                  string   strHadFileName   =   System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(Driver_Path));  
                                  HttpContext.Current.Response.AddHeader("Content-Type","application/octet-stream");  
                                  HttpContext.Current.Response.AddHeader("Content-Disposition",   "attachment;   filename="   +   strHadFileName);     //下载到客户端默认文件名  
                                  //   可以看到下载进程  
                                  HttpContext.Current.Response.AddHeader("Content-Length",   file1.Length.ToString());  
                                  string   strFullName   =   file1.FullName;  
                                  HttpContext.Current.Response.WriteFile(strFullName);  
                                  HttpContext.Current.Response.Flush();  
                                  HttpContext.Current.Response.End();  
                          }  
                          catch  
                          {  
   
   
                          }  
                  }  
   
   
   
  调用:  
   
    private   void   Button2_Click(object   sender,   System.EventArgs   e)  
                  {  
                          string   file1="API_IDECL_DBF.mdb";  
                          Interface.FileDownload(file1);  
                  }  
(上述出自:)
阅读(1571) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~