<p>I'm looking for a good method of generating an iCalendar file (*.ics) in c# (asp.net).  I've found a couple resources, but one thing that has been lacking is their support for <strong>quoted-printable</strong> fields - fields that have carriage returns and line feeds.</p>

<p>For example, if the <strong>description</strong> field isn't encoded properly, only the first line will display and possibly corrupting the rest of the information in the *.ics file.</p>

<p>I'm looking for existing classes that can generate *.ics files and/or a class that can generate <strong>quoted-printable</strong> fields.</p>

[{'answer_id': 10659, 'author': 'DevelopingChris', 'author_id': 1220, 'author_profile': 'https://Stackoverflow.com/users/1220', 'pm_score': 6, 'selected': False, 'text': '<p>I use <a href="http://sourceforge.net/projects/dday-ical/" rel="noreferrer">DDay.Ical</a>, its good stuff.\nHas the ability to open up an ical file and get its data in a nice object model. It says beta, but it works great for us.</p>\n\n<h1>Edit Nov 2016</h1>\n\n<p>This library has been deprecated, but was picked up and re-released as iCal.NET by another dev. </p>\n\n<p>Notes about the release: <a href="http://rianjs.net/2016/07/dday-ical-is-now-ical-net" rel="noreferrer">rianjs.net/2016/07/dday-ical-is-now-ical-net</a></p>\n\n<p>Source on GitHub: <a href="https://github.com/rianjs/ical.net" rel="noreferrer">github.com/rianjs/ical.net</a></p>\n'}, {'answer_id': 10729, 'author': 'Lance Fisher', 'author_id': 571, 'author_profile': 'https://Stackoverflow.com/users/571', 'pm_score': 0, 'selected': False, 'text': "<p>iCal can be complicated, so I recommend using a library.  DDay is a good free solution.  Last I checked it didn't have full support for recurring events, but other than that it looks really nice.  Definitely test the calendars with several clients.</p>\n"}, {'answer_id': 16734, 'author': 'slolife', 'author_id': 698, 'author_profile': 'https://Stackoverflow.com/users/698', 'pm_score': 1, 'selected': False, 'text': '<p>Check out <a href="http://www.codeproject.com/KB/vb/vcalendar.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/vb/vcalendar.aspx</a></p>\n\n<p>It doesn\'t handle the quoted-printable fields like you asked, but the rest of the code is there and can be modified.</p>\n'}, {'answer_id': 17550, 'author': 'Ian Oxley', 'author_id': 1904, 'author_profile': 'https://Stackoverflow.com/users/1904', 'pm_score': 4, 'selected': False, 'text': '<p>The easiest way I\'ve found of doing this is to markup your HTML using <a href="http://microformats.org/" rel="noreferrer">microformats</a>. </p>\n\n<p>If you\'re looking to generate iCalendar files then you could use the <a href="http://microformats.org/wiki/hcalendar" rel="noreferrer">hCalendar microformat</a> then include a link such as \'Add to Calendar\' that points to: </p>\n\n<p><strong><a href="http://feeds.technorati.com/events/[" rel="noreferrer">http://feeds.technorati.com/events/[</a> your page\'s full URL including the http:// ]</strong></p>\n\n<p>The Technorati page then parses your page, extracts the hCalendar info and sends the iCalendar file to the client.</p>\n'}, {'answer_id': 870249, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>According to RFC-2445, the comment and description fields are TEXT. The rules for a test field are:\n[1] A single line in a TEXT field is not to exceed 75 octets.\n[2] Wrapping is achieved by inserting a CRLF followed by whitespace.\n[3] There are several characters that must be encoded including \\ (reverse slash) ; (semicolon) , (comma) and newline. Using a \\ (reverse slash) as a delimiter gives \\ \\; \\, \\n</p>\n\n<p>Example: The following is an example of the property with formatted\n   line breaks in the property value:</p>\n\n<pre><code> DESCRIPTION:Meeting to provide technical review for "Phoenix"\n   design.\\n Happy Face Conference Room. Phoenix design team\n   MUST attend this meeting.\\n RSVP to team leader.\n</code></pre>\n'}, {'answer_id': 870351, 'author': 'azheglov', 'author_id': 105631, 'author_profile': 'https://Stackoverflow.com/users/105631', 'pm_score': 2, 'selected': False, 'text': "<p><strong>iCal</strong> (ical 2.0) and quoted-printable don't go together.</p>\n\n<p>Quoted-printable is used a lot in <strong>vCal</strong> (vCal 1.0) to represent non-printable characters, e.g. line-breaks (=0D=0A).  The default vCal encoding is 7-bit, so sometimes you need to use quoted-printable to represent non-ASCII characters (you can override the default encoding, but the other vCal-compliant communicating party is not required to understand it.)</p>\n\n<p>In <strong>iCal</strong>, special characters are represented using escapes, e.g. '\\n'.  The default encoding is UTF-8, all iCal-compliant parties must support it and that makes quoted-printable completely unnecessary in iCal 2.0 (and vCard 3.0, for that matter).</p>\n\n<p>You may need to back your customer/stakeholder to clarify the requirements.  There seems to be confusion between vCal and iCal.</p>\n"}, {'answer_id': 4763886, 'author': 'atmarx', 'author_id': 253717, 'author_profile': 'https://Stackoverflow.com/users/253717', 'pm_score': 2, 'selected': False, 'text': '<p>I wrote a shim function to handle this.  It\'s mostly compliant--the only hangup is that the first line is 74 characters instead of 75 (the 74 is to handle the space on subsequent lines)...</p>\n\n<pre><code> Private Function RFC2445TextField(ByVal LongText As String) As String\n\n     LongText = LongText.Replace("\\", "\\\\")\n     LongText = LongText.Replace(";", "\\;")\n     LongText = LongText.Replace(",", "\\,")\n\n     Dim sBuilder As New StringBuilder\n     Dim charArray() As Char = LongText.ToCharArray\n\n     For i = 1 To charArray.Length\n         sBuilder.Append(charArray(i - 1))\n         If i Mod 74 = 0 Then sBuilder.Append(vbCrLf &amp; " ")\n     Next\n\n     Return sBuilder.ToString\n\n End Function\n</code></pre>\n\n<p>I use this for the summary and description on our ICS feed.  Just feed the line with the field already prepended (e.g. LongText = "SUMMARY:Event Title").  As long as you set caching decently long, it\'s not too expensive of an operation.</p>\n'}, {'answer_id': 43877173, 'author': 'Manpreet Singh Dhillon', 'author_id': 3495713, 'author_profile': 'https://Stackoverflow.com/users/3495713', 'pm_score': 0, 'selected': False, 'text': '<p>i know it is too late, but it may help others. in my case i wrote following text file with .ics extension </p>\n\n<pre><code>BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Calendly//EN\nCALSCALE:GREGORIAN\nMETHOD:PUBLISH\nBEGIN:VEVENT\nDTSTAMP:20170509T164109Z\nUID:your id-11273661\nDTSTART:20170509T190000Z\nDTEND:20170509T191500Z\nCLASS:PRIVATE\nDESCRIPTION:Event Name: 15 Minute Meeting\\nDate &amp; Time: 03:00pm - 03:15pm (\n Eastern Time - US &amp; Canada) on Tuesday\\, May 9\\, 2017\\n\\nBest Phone Number\n  To Reach You :: xxxxxxxxx\\n\\nany "link": https://wwww.yahoo.com\\n\\n\nSUMMARY:15 Minute Meeting\nTRANSP:OPAQUE\nEND:VEVENT\nEND:VCALENDAR\n</code></pre>\n\n<p>it worked for me.</p>\n'}, {'answer_id': 46837390, 'author': 'VDWWD', 'author_id': 5836671, 'author_profile': 'https://Stackoverflow.com/users/5836671', 'pm_score': 2, 'selected': False, 'text': '<p>I\'m missing an example with custom time zones. So here a snippet that show how you can set a time zone in the ics (and send it to the browser in asp.net).</p>\n\n<pre><code>//set a couple of variables for demo purposes\nDateTime IcsDateStart = DateTime.Now.AddDays(2);\nDateTime IcsDateEnd = IcsDateStart.AddMinutes(90);\nstring IcsSummary = "ASP.Net demo snippet";\nstring IcsLocation = "Amsterdam (Netherlands)";\nstring IcsDescription = @"This snippes show you how to create a calendar item file (.ics) in ASP.NET.\\nMay it be useful for you.";\nstring IcsFileName = "MyCalendarFile";\n\n//create a new stringbuilder instance\nStringBuilder sb = new StringBuilder();\n\n//begin the calendar item\nsb.AppendLine("BEGIN:VCALENDAR");\nsb.AppendLine("VERSION:2.0");\nsb.AppendLine("PRODID:stackoverflow.com");\nsb.AppendLine("CALSCALE:GREGORIAN");\nsb.AppendLine("METHOD:PUBLISH");\n\n//create a custom time zone if needed, TZID to be used in the event itself\nsb.AppendLine("BEGIN:VTIMEZONE");\nsb.AppendLine("TZID:Europe/Amsterdam");\nsb.AppendLine("BEGIN:STANDARD");\nsb.AppendLine("TZOFFSETTO:+0100");\nsb.AppendLine("TZOFFSETFROM:+0100");\nsb.AppendLine("END:STANDARD");\nsb.AppendLine("END:VTIMEZONE");\n\n//add the event\nsb.AppendLine("BEGIN:VEVENT");\n\n//with a time zone specified\nsb.AppendLine("DTSTART;TZID=Europe/Amsterdam:" + IcsDateStart.ToString("yyyyMMddTHHmm00"));\nsb.AppendLine("DTEND;TZID=Europe/Amsterdam:" + IcsDateEnd.ToString("yyyyMMddTHHmm00"));\n\n//or without a time zone\n//sb.AppendLine("DTSTART:" + IcsDateStart.ToString("yyyyMMddTHHmm00"));\n//sb.AppendLine("DTEND:" + IcsDateEnd.ToString("yyyyMMddTHHmm00"));\n\n//contents of the calendar item\nsb.AppendLine("SUMMARY:" + IcsSummary + "");\nsb.AppendLine("LOCATION:" + IcsLocation + "");\nsb.AppendLine("DESCRIPTION:" + IcsDescription + "");\nsb.AppendLine("PRIORITY:3");\nsb.AppendLine("END:VEVENT");\n\n//close calendar item\nsb.AppendLine("END:VCALENDAR");\n\n//create a string from the stringbuilder\nstring CalendarItemAsString = sb.ToString();\n\n//send the ics file to the browser\nResponse.ClearHeaders();\nResponse.Clear();\nResponse.Buffer = true;\nResponse.ContentType = "text/calendar";\nResponse.AddHeader("content-length", CalendarItemAsString.Length.ToString());\nResponse.AddHeader("content-disposition", "attachment; filename=\\"" + IcsFileName + ".ics\\"");\nResponse.Write(CalendarItemAsString);\nResponse.Flush();\nHttpContext.Current.ApplicationInstance.CompleteRequest();\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/10658', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/519/']