2010-10-09 61 views
1

如何強制下載服務器上文本文件的對話框?如何強制在服務器上爲文本文件下載對話框?

當我用一擊代碼,這樣的對話窗口是爲aspx文件......(爲什麼?)

string FileBankPhysicalFolder = Server.MapPath("~/FileBanks/"); 
    string Name = "FileBank_" + "Melli_" + Session["Co_ID"].ToString() + "_" + RadcbDateOfPardakht.SelectedValue.Replace('/',',') + ".txt"; 
    string FileBankPath = FileBankPhysicalFolder + Name; 
    string Content = Header + Body; 
    System.IO.File.WriteAllText(FileBankPath, Content); 

    Response.ContentType = "text/plain"; 
    Response.AppendHeader("Content-Disposition", "attachment;" + Name); 
    Response.WriteFile(FileBankPath); 
    Response.End(); 

我怎樣才能解決這個問題?

回答

2

您應該發送強制下載標題以及文件。我不知道你會怎麼做,在ASP但基本上你要讀一些ASP內置功能的文件,那麼它輸出到瀏覽器安裝

Content-Type: application/force-download; 
Content-Disposition: attachment; filename=\yourfile.txt 

您的代碼來看:

Response.AppendHeader("Content-Type", "application/force-download;"); 
Response.AppendHeader("Content-Disposition", "attachment; filename="+ Name); 

乾杯!

+0

非常感謝... – LostLord 2010-10-09 16:01:47

+0

不客氣的朋友:) – Claudiu 2010-10-09 16:06:43

相關問題