【发布时间】:2015-09-08 16:32:33
【问题描述】:
我想在我的 ASP.NET 应用程序中生成一个 ICS 文件 (iCalendar),然后在不显示文件对话框“打开/保存/取消”的情况下自动打开它。
此生成的文件将由用户的默认应用程序打开这些 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/outlook 或 Content-Disposition : attachment; 而不是 Content-Disposition : inline; .... 没有成功。
此代码用于通过对话框打开 ICS。但我会自动打开它而不显示此对话框。
如何做到这一点?
【问题讨论】: