从代码创建.ics文件有时会给出“文件<文件名> [<索引>]。ics”不是有效的互联网日历文件</index> </filename>

时间:2010-05-19 07:44:41

标签: asp.net response outlook-2007 icalendar

我正在构建一个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中打开事件时通常会收到错误,并且第二次它会正常工作。

有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

似乎最初的Response.Clear()和End之前的Flush解决了问题......