从代码创建 .ics 文件有时会给出“The file[].ics”不是有效的互联网日历文件

发布于 2024-09-02 05:39:00 字数 1465 浏览 11 评论 0原文

我正在构建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自此以后,行同陌路 2024-09-09 05:39:00

似乎一开始的 Response.Clear() 和 End 之前的 Flush 解决了问题......

It seems like Response.Clear() in the very beginning and Flush before End solves the problem...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文