Click here to Skip to main content
11,789,710 members (62,270 online)
Click here to Skip to main content

Generating vCalendar files (.vcs) to download in ASP.NET

, 9 Nov 2004 96.6K 52
Rate this:
Please Sign up or sign in to vote.
VB.NET code for webpage to ask to download calendar items. Can be used for any calendars that supports vCalendar such as Outlook.

Sample Image - vcalendarfiletodownload.jpg


Very simple to create vCalendar files, it is basically like creating text files, the only difference is the format.

In this example, a physical file is not created (no need to clean up a temp directory afterwards), the file is kept in memory using memory stream. Once the file is created in memory, it is sent for download.

vCalendar is using UTC, so the function ToUniversalTime is used to convert the local time to UTC.

<%@ Page Language="vb" ContentType="text/html" 
    ResponseEncoding="iso-8859-1" Debug="False" trace="False"%>
<%@ import Namespace="System.IO" %>

<script runat="server"> 
Sub Page_Load(Sender As Object, E As EventArgs) 

   Dim beginDate as Date = #01/07/2005 4:00 PM#

   Dim endDate as Date  = #01/07/2005 6:00 PM#
   Dim myLocation as String = "Computer Room"
   Dim mySubject as String = "Training"
   Dim myDescription as String = "Event details" 
   Dim mStream As new MemoryStream()
   Dim writer As new StreamWriter(mStream)
   writer.AutoFlush = true 
   writer.WriteLine("PRODID:-//Flo Inc.//FloSoft//EN")
   writer.WriteLine("DTSTART:" & _
            beginDate.ToUniversalTime.ToString("yyyyMMdd\THHmmss\Z") )
   writer.WriteLine("DTEND:" & _
           endDate.ToUniversalTime.ToString("yyyyMMdd\THHmmss\Z") )
   writer.WriteLine("LOCATION:" & myLocation)
   writer.WriteLine("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" & myDescription)
   writer.WriteLine("SUMMARY:" & mySubject) 
   Response.Clear() 'clears the current output content from the buffer
   Response.AppendHeader("Content-Disposition", _
            "attachment; filename=Add2Calendar.vcs")
   Response.AppendHeader("Content-Length", mStream.Length.ToString())
   Response.ContentType = "application/download"
End Sub


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Florent Boulanger
Web Developer
United States United States
Broad engineering background with business knowledge (graduated from a top French engineering school training entrepreneurs), and excellent relationship skills that Flo utilizes in the I.T. field to streamline/improve company processes.

From web to embedded programming, from a big-5 consulting company to a local hospital, Flo shares his time between development and implementation lead.
Work with ASP.NET, VB.NET, LDAP, SQL Server, Oracle, MySQL...

You may also be interested in...

Comments and Discussions

GeneralAuto Updates Pin
justin.moses6-Feb-08 13:08
memberjustin.moses6-Feb-08 13:08 
GeneralMemorystream for email attachments Pin
Minessence29-Apr-05 13:53
memberMinessence29-Apr-05 13:53 
GeneralCR's Pin
SouthAfrican21-Jan-05 5:45
memberSouthAfrican21-Jan-05 5:45 
GeneralRe: CR's Pin
Florent Boulanger2-Feb-05 11:50
memberFlorent Boulanger2-Feb-05 11:50 
GeneralRe: CR's Pin
JB12110-Oct-05 7:14
memberJB12110-Oct-05 7:14 
GeneralRe: CR's Pin
JB12110-Oct-05 7:34
memberJB12110-Oct-05 7:34 
GeneralGood job and thanks Pin
mcflee22-Nov-04 3:07
membermcflee22-Nov-04 3:07 
QuestionWorks in Firefox and not in IE?? Pin
Cimedaca12-Nov-04 3:46
memberCimedaca12-Nov-04 3:46 
AnswerRe: Works in Firefox and not in IE?? Pin
Florent Boulanger3-Dec-04 11:14
memberFlorent Boulanger3-Dec-04 11:14 
General[Message Deleted] Pin
Dan Colasanti10-Nov-04 20:07
memberDan Colasanti10-Nov-04 20:07 
GeneralRe: Source Code? Pin
mcflee22-Nov-04 0:37
membermcflee22-Nov-04 0:37 
GeneralWindow media host control in Visual Studio. Pin
khoaduongminh21-Oct-04 16:32
memberkhoaduongminh21-Oct-04 16:32 
GeneralSimilar articles Pin
Chris Becker21-Oct-04 9:41
memberChris Becker21-Oct-04 9:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1509028.1 | Last Updated 9 Nov 2004
Article Copyright 2004 by Florent Boulanger
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid