2015-09-08 57 views
0

我想在我的ASP.NET應用程序中生成一個ICS文件(iCalendar),然後自動打開它而不顯示文件對話框「打開/保存/取消」。ASP.NET - 打開文件時不顯示對話框

此生成的文件將由用戶的這些ics文件的默認應用程序打開。

我嘗試這樣做:

String sICSPath = Server.MapPath(".") + @"\Files\Test.ics"; 
String sFullText = File.ReadAllText(sICSPath); 
sFullText = sFullText.Replace("#NAME#", "MyName"); 

this.Response.ContentType = "Content-Type: text/Calendar"; 
this.Response.AddHeader("Cache-Control", "no-cache, must-revalidate"); 
this.Response.AddHeader("Pragma", "no-cache"); 
this.Response.AddHeader("Content-Disposition", "inline; filename=calendar.ics"); 
this.Response.Write(sFullText); 
this.Response.End(); 

我試着像Content-Type : application/outlookContent-Disposition : attachment;代替Content-Disposition : inline;其他頭....沒有成功。

此代碼可用於通過對話框打開ICS。但是我會自動打開它而不顯示這個對話框。

這可以怎麼做?

回答

3

你不能那樣做。用戶的瀏覽器設置決定他們是否會看到保存對話框,或者直接保存並打開。

想象一下,假設它是否按照你想要的那樣工作 - 這將是一個巨大的安全漏洞。

相關問題