2010-11-03 47 views
0

我使用下面的代碼下載PDF文檔,但保存爲模式,但IE中存在問題, 任何人都可以解決此問題?下載另存爲對話框的PDF文檔

private void DownloadFile(string fname, bool forceDownload) 
{ 
    string path = MapPath(fname); 
    string name = Path.GetFileName(fname); 
    string ext = Path.GetExtension(fname); 
    string type = ""; 
    Response.ClearHeaders(); 
    Response.ClearContent(); 
    // set known types based on file extension 
    if (ext != null) 
    { 
     switch (ext.ToLower()) 
     { 
      case ".htm": 
      case ".html": 
       type = "text/HTML"; 
       break; 

      case ".txt": 
       type = "text/plain"; 
       break; 

      case ".pdf": 
       type = "application/pdf"; 
       break; 
      case ".doc": 
      case ".docx": 
      case ".rtf": 
       type = "Application/msword"; 
       break; 
     } 
    } 
    if (forceDownload) 
    { 
     Response.AppendHeader("content-disposition", "attachment; filename=" + name); 
    } 
    if (type != "") 
    { 
     Response.ContentType = type; 
     Response.WriteFile(path); 
     Response.End(); 
    } 

} 

感謝

阿西姆哈什米

+0

問題是什麼?是拋出異常或JS錯誤,或文件操作系統沒有下載到客戶端電腦? – 2010-11-03 14:10:51

回答

0

也許是因爲你使用SSL?
選中此項:http://support.microsoft.com/kb/316431

+0

謝謝阿里夫, 我想單獨的對話框下載pdf文件, 我的代碼與Firfox一起工作,但IE瀏覽器沒有響應 – Asim 2010-11-04 13:53:15

相關問題