Creating iCal files in C #

I am looking for a good way to create an iCalendar file (* .ics) in C # (asp.net). I found a couple of resources, but one thing that was missing was the support for quoted-printable fields - with carriage returns and linear channels.

For example, if the description field is incorrectly encoded, only the first line will be displayed and, possibly, the rest of the information in the * .ics file will be damaged.

I am looking for existing classes that can generate * .ics files and / or a class that can generate quoted-printable fields.

+73
c # icalendar
Aug 14 '08 at 4:07
source share
9 answers

I use DDay.Ical , its good stuff. Has the ability to open the ical file and get its data in a good object model. He's talking about beta, but it works great for us.

Edit November 2016

This library is deprecated, but was selected and republished as an iCal.NET by another developer.

Release Notes: rianjs.net/2016/07/dday-ical-is-now-ical-net

Source on GitHub: github.com/rianjs/ical.net

+70
Aug 14 '08 at 4:09
source share

The easiest way to do this is with HTML markup using microformats .

If you want to generate iCalendar files, you can use hcalendar microformat and then include a link such as Add to Calendar, which points to:

http://feeds.technorati.com/events/ [ full URL of your page, including http: //]

The Technorati page then analyzes your page, retrieves the hCalendar information, and sends the iCalendar file to the client.

+12
Aug 20 '08 at 8:02
source share

I wrote a pad function to handle this. Basically this is compatible - the only hang is that the first line is 74 characters instead of 75 (74 - to handle the space on subsequent lines) ...

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 

I use this to summarize and describe our ICS feed. Just feed the line with the field already added (for example, LongText = "SUMMARY: Event Name"). As long as you install caching decently for a long time, it is not too expensive for the operation.

+3
Jan 21 2018-11-21T00:
source share

iCal (ical 2.0) and print quotes do not go together.

Quoted-printable is used in vCal (vCal 1.0) to represent non-printable characters, for example. line breaks (= 0D = 0A). The default encoding of vCal is 7 bits, so sometimes you need to use quotation marks to print without ASCII characters (you can override the default encoding, but another one that does not match vCal should not understand it.)

In iCal, special characters are represented using screens, for example. '\ P'. The default encoding is UTF-8, all parties supporting iCal must support it, and this makes quotation marks unnecessary for printing in iCal 2.0 (and vCard 3.0, for that matter).

You may need to return your client / interested party to clarify the requirements. There seems to be a confusion between vCal and iCal.

+2
May 15, '09 at 19:11
source share

Check out http://www.codeproject.com/KB/vb/vcalendar.aspx

It does not process quotation marks as you requested, but the rest of the code exists and can be changed.

+1
Aug 19 '08 at 18:51
source share

According to RFC-2445, the comment and description fields are TEXT. Rules for the test field: [1] One line in the TEXT field should not exceed 75 octets. [2] A wrapper is achieved by inserting a CRLF followed by a space. [3] There are several characters that must be encoded, including \ (backslash); (semicolon), (comma) and a new line. Using the \ (backslash) character as a delimiter gives \\; \, \ n

Example. The following is an example of a property with formatting line breaks in the property value:

  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. 
+1
May 15 '09 at 18:47
source share

iCal can be complicated, so I recommend using the library. DDay is a good free solution. The last thing I checked, it did not have full support for recurring events, but other than that it looks very good. Definitely check calendars by multiple clients.

0
Aug 14 '08 at 6:10
source share

I know it's too late, but it can help others. in my case I wrote the following text file with a .ics extension

 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 

it worked for me.

0
May 09 '17 at 18:19
source share

I miss the timezone example. So here is a snippet that shows how you can set the timezone in ics (and send it to the browser in 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(); 
0
19 Oct '17 at 19:23
source share



All Articles