之前曾經有要讓使用者一定要出現另存新檔的視窗

像下面這樣.....因為IE有時候好像設定會跑掉....或是有人不想出現視窗

2010082401.jpg

有一個地方應該是可以設定不過我很少去使用這個

沒有這種需求....不過說一下在哪裡好了

在:我的電腦->工具->資料夾選項->檔案類型->

(如下圖我是用TXT就看要設定是的哪一種福檔名就選哪一種例:Excel->xls 或Word->doc)

2010082402.jpg

點選(反白)按進階之後就如下圖把下載之後進行開啟確認 "不勾選" 就可以了......

(不確定是不是一定有效啦)

2010082403.jpg

如果要強制出現的話程式碼是....

 
 //要下載的檔案可動態
 string filename = "C:\\xxx.txt";

 string saveFileName = "xxx.txt";
 int intStart = filename.LastIndexOf("\\") + 1;
 saveFileName = filename.Substring(intStart, filename.Length - intStart);

 System.IO.FileInfo fi = new System.IO.FileInfo(filename);
 string fileextname = fi.Extension;
 string DEFAULT_CONTENT_TYPE = "application/unknow";
 Microsoft.Win32.RegistryKey regkey, fileextkey;
 string filecontenttype;
 try
 {
   regkey = Microsoft.Win32.Registry.ClassesRoot;
   fileextkey = regkey.OpenSubKey(fileextname);
   filecontenttype = fileextkey.GetValue("Content Type", DEFAULT_CONTENT_TYPE).ToString();
 }
 catch
 {
   filecontenttype = DEFAULT_CONTENT_TYPE;
 }
 Response.Clear();
 Response.Charset = "utf-8";
 Response.Buffer = true;
 this.EnableViewState = false;
 Response.ContentEncoding = System.Text.Encoding.UTF8;
 Response.AppendHeader("Content-Disposition", "attachment;filename=" + saveFileName);
 Response.ContentType = filecontenttype;

 Response.WriteFile(filename);
 Response.Flush();
 Response.Close();
 Response.End();

參考:

http://blog.joycode.com/uestc95/archive/2004/05/25/22494.aspx

arrow
arrow
    全站熱搜

    鴨爸 發表在 痞客邦 留言(0) 人氣()