从代码创建 .ics 文件有时会给出“The file[].ics”不是有效的互联网日历文件
我正在构建一个 ASP 站点,在其中使用 response.write 创建一个 ics 文件,用户可以在其中选择打开或保存事件的对话框。当用户选择打开时,Outlook 有时会给出错误“文件 [].ics”不是有效的 Internet 日历文件”。写入响应的始终是相同的事件。代码如下所示:
this.Response.ContentType = "text/calendar";
this.Response.AddHeader("Cache-Control", "no-cache, must-revalidate");
this.Response.AddHeader("Pragma", "no-cache");
this.Response.Expires = -1;
this.Response.AddHeader("Content-disposition", string.Format("attachment; filename={0}.ics",filename));
this.Response.Write("BEGIN:VCALENDAR");
this.Response.Write("\nVERSION:2.0");
this.Response.Write("\nMETHOD:PUBLISH");
this.Response.Write("\nBEGIN:VEVENT");
this.Response.Write("\nType:Single Meeting");
this.Response.Write("\nORGANIZER:MAILTO:" + organizer);
this.Response.Write("\nDTSTART:" + startDate.ToUniversalTime().ToString(DateFormat));
this.Response.Write("\nDTEND:" + endDate.ToUniversalTime().ToString(DateFormat));
this.Response.Write("\nLOCATION:" + location);
this.Response.Write("\nUID:" + Guid.NewGuid().ToString());
this.Response.Write("\nDTSTAMP:" + DateTime.Now.ToUniversalTime().ToString(DateFormat));
this.Response.Write("\nSUMMARY:" + summary);
this.Response.Write("\nDESCRIPTION:" + description);
this.Response.Write("\nPRIORITY:5");
this.Response.Write("\nCLASS:PUBLIC");
this.Response.Write("\nEND:VEVENT");
this.Response.Write("\nEND:VCALENDAR");
this.Response.End();
我通常得到我第一次尝试在 Outlook 中打开该事件时出现错误,第二次时出现此错误
有人知道如何解决此问题吗?
I am building an ASP site where I use response.write to create an ics file where a user can choose open or save dialog for the event. When the user chooses open, Outlook sometimes gives the error "The file [].ics" is not a valid internet Calendar file". It is always the same event that is written to the response. The code looks like this:
this.Response.ContentType = "text/calendar";
this.Response.AddHeader("Cache-Control", "no-cache, must-revalidate");
this.Response.AddHeader("Pragma", "no-cache");
this.Response.Expires = -1;
this.Response.AddHeader("Content-disposition", string.Format("attachment; filename={0}.ics",filename));
this.Response.Write("BEGIN:VCALENDAR");
this.Response.Write("\nVERSION:2.0");
this.Response.Write("\nMETHOD:PUBLISH");
this.Response.Write("\nBEGIN:VEVENT");
this.Response.Write("\nType:Single Meeting");
this.Response.Write("\nORGANIZER:MAILTO:" + organizer);
this.Response.Write("\nDTSTART:" + startDate.ToUniversalTime().ToString(DateFormat));
this.Response.Write("\nDTEND:" + endDate.ToUniversalTime().ToString(DateFormat));
this.Response.Write("\nLOCATION:" + location);
this.Response.Write("\nUID:" + Guid.NewGuid().ToString());
this.Response.Write("\nDTSTAMP:" + DateTime.Now.ToUniversalTime().ToString(DateFormat));
this.Response.Write("\nSUMMARY:" + summary);
this.Response.Write("\nDESCRIPTION:" + description);
this.Response.Write("\nPRIORITY:5");
this.Response.Write("\nCLASS:PUBLIC");
this.Response.Write("\nEND:VEVENT");
this.Response.Write("\nEND:VCALENDAR");
this.Response.End();
I usually get the error the first time I try to open the event in Outlook, and the it works the second time.
Does anyone know how to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎一开始的 Response.Clear() 和 End 之前的 Flush 解决了问题......
It seems like Response.Clear() in the very beginning and Flush before End solves the problem...