2014-03-13 31 views
1

我需要從服務器下載文件。它的代碼如下所示:在mozilla中顯示打開/下載文件選項

public void ProcessRequest(HttpContext context) 
{ 
    string fileName = context.Request.QueryString["fileName"]; 

    string filePath = HostingEnvironment.ApplicationPhysicalPath + "/TempFolder/" + fileName; 

    if (File.Exists(filePath)) 
    { 
     context.Response.ContentType = "application/octet-stream"; 
     context.Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName); 

     using (FileStream fileStream = new FileStream(filePath, FileMode.Open)) 
     { 
      int _READ_LEN = 3000; 

      int bLength = _READ_LEN; 
      BinaryReader bReader = new BinaryReader(fileStream); 

      if (bReader.BaseStream.Length < _READ_LEN) 
       bLength = (int)bReader.BaseStream.Length; 

      while (bReader.BaseStream.Position != bReader.BaseStream.Length) 
      { 
       context.Response.BinaryWrite(bReader.ReadBytes(bLength)); 

       if ((bReader.BaseStream.Length - bReader.BaseStream.Position) < _READ_LEN) 
        bLength = (int)(bReader.BaseStream.Length - bReader.BaseStream.Position); 
      } 
     } 

     context.Response.Flush(); 

     File.Delete(filePath); 
    } 
} 

當我嘗試下載文件在Mozilla,它會自動下載文件,而不要求爲開/下載文件,而它顯示了該選項,在IE工作時。 我需要這個選項才能在Mozilla中顯示。 我試圖搜索的東西,但找不到任何有用的東西。 任何人都可以請建議一個解決方案?

回答

0

如果Mozilla Firefox自動下載文件而不詢問目的地,它很可能配置爲以這種方式工作。查看Mozilla Firefox Help瞭解更多信息。

0

Afaik這是瀏覽器相關的行爲(瀏覽器設置包括處理不同文件類型的方式)。

如果您希望採用獨立於瀏覽器的方式處理此問題,建議您使用例如一個模式彈出框,提示用戶選擇。根據答案,您可以構建一個可以在文件處理程序中處理的查詢字符串。

相關問題