例如,如果description字段没有正确编码,只有第一行会显示,并可能破坏*.ics文件中其余信息。
我正在寻找能够生成*.ics文件的现有类和/或能够生成quoted-printable字段的类。
我使用 DDay.Ical,这是一款很好的工具。
它能够打开一个ical文件,并将数据以漂亮的对象模型呈现。虽然它标注为beta版本,但对于我们来说它已经非常好用了。
此库已被弃用,不过已由其他开发者接手并作为iCal.NET重新发布。
有关发布的说明:rianjs.net/2016/07/dday-ical-is-now-ical-net
GitHub源代码:github.com/rianjs/ical.net
我发现最简单的方法是使用微格式标记你的HTML。
如果您想生成iCalendar文件,那么您可以使用hCalendar微格式,然后包括一个指向“添加到日历”的链接,该链接指向:
http://feeds.technorati.com/events/[包括http://在内的页面完整URL]
然后Technorati页面会解析您的页面,提取hCalendar信息并将iCalendar文件发送给客户端。
我编写了一个shim函数来处理这个问题。它基本上是兼容的 - 唯一的问题是第一行只有74个字符而不是75个(74是为了处理后续行上的空格)...
Private Function RFC2445TextField(ByVal LongText As String) As String
LongText = LongText.Replace("\", "\\")
LongText = LongText.Replace(";", "\;")
LongText = LongText.Replace(",", "\,")
Dim sBuilder As New StringBuilder
Dim charArray() As Char = LongText.ToCharArray
For i = 1 To charArray.Length
sBuilder.Append(charArray(i - 1))
If i Mod 74 = 0 Then sBuilder.Append(vbCrLf & " ")
Next
Return sBuilder.ToString
End Function
我在我们的ICS订阅中使用这个来作为摘要和描述。只需提前加上字段并将其输入到该行中(例如,LongText =“SUMMARY:事件标题”)。 只要设置缓存时间足够长,它就不会太耗费资源。
我需要一个关于自定义时区的示例。下面是一个片段,展示了如何在ics中设置时区(并在asp.net中将其发送到浏览器)。
//set a couple of variables for demo purposes
DateTime IcsDateStart = DateTime.Now.AddDays(2);
DateTime IcsDateEnd = IcsDateStart.AddMinutes(90);
string IcsSummary = "ASP.Net demo snippet";
string IcsLocation = "Amsterdam (Netherlands)";
string IcsDescription = @"This snippes show you how to create a calendar item file (.ics) in ASP.NET.\nMay it be useful for you.";
string IcsFileName = "MyCalendarFile";
//create a new stringbuilder instance
StringBuilder sb = new StringBuilder();
//begin the calendar item
sb.AppendLine("BEGIN:VCALENDAR");
sb.AppendLine("VERSION:2.0");
sb.AppendLine("PRODID:stackoverflow.com");
sb.AppendLine("CALSCALE:GREGORIAN");
sb.AppendLine("METHOD:PUBLISH");
//create a custom time zone if needed, TZID to be used in the event itself
sb.AppendLine("BEGIN:VTIMEZONE");
sb.AppendLine("TZID:Europe/Amsterdam");
sb.AppendLine("BEGIN:STANDARD");
sb.AppendLine("TZOFFSETTO:+0100");
sb.AppendLine("TZOFFSETFROM:+0100");
sb.AppendLine("END:STANDARD");
sb.AppendLine("END:VTIMEZONE");
//add the event
sb.AppendLine("BEGIN:VEVENT");
//with a time zone specified
sb.AppendLine("DTSTART;TZID=Europe/Amsterdam:" + IcsDateStart.ToString("yyyyMMddTHHmm00"));
sb.AppendLine("DTEND;TZID=Europe/Amsterdam:" + IcsDateEnd.ToString("yyyyMMddTHHmm00"));
//or without a time zone
//sb.AppendLine("DTSTART:" + IcsDateStart.ToString("yyyyMMddTHHmm00"));
//sb.AppendLine("DTEND:" + IcsDateEnd.ToString("yyyyMMddTHHmm00"));
//contents of the calendar item
sb.AppendLine("SUMMARY:" + IcsSummary + "");
sb.AppendLine("LOCATION:" + IcsLocation + "");
sb.AppendLine("DESCRIPTION:" + IcsDescription + "");
sb.AppendLine("PRIORITY:3");
sb.AppendLine("END:VEVENT");
//close calendar item
sb.AppendLine("END:VCALENDAR");
//create a string from the stringbuilder
string CalendarItemAsString = sb.ToString();
//send the ics file to the browser
Response.ClearHeaders();
Response.Clear();
Response.Buffer = true;
Response.ContentType = "text/calendar";
Response.AddHeader("content-length", CalendarItemAsString.Length.ToString());
Response.AddHeader("content-disposition", "attachment; filename=\"" + IcsFileName + ".ics\"");
Response.Write(CalendarItemAsString);
Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
示例:以下是具有格式化行断点的属性值的示例:
DESCRIPTION:Meeting to provide technical review for "Phoenix"
design.\n Happy Face Conference Room. Phoenix design team
MUST attend this meeting.\n RSVP to team leader.
请查看http://www.codeproject.com/KB/vb/vcalendar.aspx
它不能处理您要求的quoted-printable字段,但其余代码都在那里,可以进行修改。
iCal 可能会很复杂,因此我建议使用库。DDay 是一个不错的免费解决方案。据我上次检查,它没有完全支持重复事件,但除此之外看起来非常好。一定要使用多个客户端测试日历。
我知道现在可能有点晚了,但这可能会帮助其他人。在我的情况下,我编写了一个带有.ics扩展名的文本文件。
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Calendly//EN
CALSCALE:GREGORIAN
METHOD:PUBLISH
BEGIN:VEVENT
DTSTAMP:20170509T164109Z
UID:your id-11273661
DTSTART:20170509T190000Z
DTEND:20170509T191500Z
CLASS:PRIVATE
DESCRIPTION:Event Name: 15 Minute Meeting\nDate & Time: 03:00pm - 03:15pm (
Eastern Time - US & Canada) on Tuesday\, May 9\, 2017\n\nBest Phone Number
To Reach You :: xxxxxxxxx\n\nany "link": https://wwww.yahoo.com\n\n
SUMMARY:15 Minute Meeting
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
这对我有用。