title: How to create .ics file programmatically?
body: <p>How can I create an icalendar file with minimum data, I try to make it as the following but somethings wrong, when I try to import to my Google calendar, it says Events successfully imported but I cant see those event on my calendar             </p>
  
  <pre><code>    strResult.Append("BEGIN:VCALENDAR" &amp; vbCrLf)           
  
      strResult.Append("VERSION:2.0" &amp; vbCrLf)
  
      strResult.Append("METHOD:PUBLISH" &amp; vbCrLf)
  
      While rst1.Read
          strResult.Append("BEGIN:VEVENT" &amp; vbCrLf)
  
          strResult.Append("DTSTART: " &amp; CDate(getLeave_date_start(CStr(rst1.getInteger("inq_id")), g_dom_id)).ToUniversalTime().ToString("yyyyMMddTHHmmssZ") &amp; vbCrLf)    
  
          strResult.Append("DTEND: " &amp; CDate(getLeave_date_end(CStr(rst1.getInteger("inq_id")), g_dom_id)).ToUniversalTime().ToString("yyyyMMddTHHmmssZ") &amp; vbCrLf)
  
          strResult.Append("SUMMARY: " &amp; rst1.getString("inq_name") &amp; vbCrLf)
  
          strResult.Append("UID: " &amp; rst1.getInteger("inq_id") &amp; vbCrLf)
  
          strResult.Append("CLASS:PUBLIC" &amp; vbCrLf)
  
          strResult.Append("END:VEVENT" &amp; vbCrLf)
  
      End While
      strResult.Append("END:VCALENDAR" &amp; vbCrLf)
  
      WriteCalendar(strResult)
  </code></pre>
  
  <p>I wrote a function WriteCalendar as follows</p>
  
  <pre><code>Private Sub WriteCalendar(ByVal data As String)
      Dim response As HttpResponse = Page.Response
      response.Clear()
      response.Buffer = True
      response.ContentType = "text/calendar"
      response.ContentEncoding = Encoding.UTF8
      response.Charset = "utf-8"
      response.AddHeader("Content-Disposition", "attachment;filename=""" &amp; "icalendarTest" &amp; ".ics""")
      response.Write(data)
      response.[End]()
  End Sub
  </code></pre>
  
  <p>I download the file and see my events but when it comes to importing to Google Calendar, it says 6 events imported successfully but I cant see them on my calendar</p>
  
  <p>The output icalendarTest.ics</p>
  
  <pre><code>BEGIN:VCALENDAR  
  VERSION:2.0  
  METHOD:PUBLISH  
  BEGIN:VEVENT  
  DTSTART: 20110107T060000Z  
  DTEND: 20110109T080000Z  
  SUMMARY: ayin yedisinden dokuzuna  
  UID: 9  
  CLASS:PUBLIC  
  END:VEVENT  
  BEGIN:VEVENT
  DTSTART: 20110119T103000Z  
  DTEND: 20110119T150000Z  
  SUMMARY: tek gunluk ondokuz  
  UID: 10  
  CLASS:PUBLIC  
  END:VEVENT  
  BEGIN:VEVENT  
  DTSTART: 20110213T080000Z  
  DTEND: 20110213T160000Z  
  SUMMARY: Mijn Event  
  UID: 21  
  CLASS:PUBLIC  
  END:VEVENT  
  BEGIN:VEVENT  
  DTSTART: 20110301T083000Z  
  DTEND: 20110302T110000Z  
  SUMMARY: Mart kapidan baktirir  
  UID: 26  
  CLASS:PUBLIC  
  END:VEVENT  
  BEGIN:VEVENT  
  DTSTART: 20110117T080000Z  
  DTEND: 20110117T120000Z  
  SUMMARY: Neyse bi oncesi olsun  
  UID: 27  
  CLASS:PUBLIC  
  END:VEVENT  
  BEGIN:VEVENT  
  DTSTART: 20110121T130000Z  
  DTEND: 20110121T180000Z  
  SUMMARY: ocak 21i  
  UID: 31  
  CLASS:PUBLIC  
  END:VEVENT  
  END:VCALENDAR  
  </code></pre>