Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
Summary: Use Microsoft Visual Studio 2005 to create an ASP.NET 2.0 Web site that can create and send an Internet Calendar appointment to add to a Microsoft Office Outlook 2007 calendar.
Applies to: 2007 Microsoft Office system, Microsoft Office Outlook 2007
Joel Krist, Akona Systems
September 2007
Code It | Read It | Explore It
Code It
To show how to create an ASP.NET Web site that has the ability to create and send an Internet Calendar appointment, this article walks through three key steps:
Creating an ASP.NET 2.0 Web Site project in Visual Studio 2005.
Creating a Web form for the site that lets a user specify a summary, description, and start or end dates and times for a calendar appointment.
Adding code to the Web form's code file that implements the Internet Calendar appointment creation and sending functionality.
Creating an ASP.NET 2.0 Web Site Project in Visual Studio 2005
Visual Studio 2005 enables you to create a Web site by using the ASP.NET Web Site template.
To create an ASP.NET Web Site project in Visual Studio 2005
Start Visual Studio.
On the File menu, click New Web Site.
In the New Web Site dialog box, click the ASP.NET Web Site template.
For Location, select HTTP or File System.
Specify a path or URL for the Web site.
For Language, click Visual C# or Visual Basic, and then click OK.
Visual Studio generates an ASP.NET Web Site project with a single Web form named Default.aspx, and a code file named either Default.aspx.cs or Default.aspx.vb, depending on the language selected.
Creating a Calendar Event Properties Web Form
By creating a Web form, a user can specify the properties of a calendar appointment, as shown in Figure 1.
To create a Calendar Event Web form
- Open the Default.aspx file and replace all of the code between the <body> and </body> tags with the following code.
<form id="form1" runat="server">
<div style="font-family: Arial" align="center">
<table>
<tr>
<td align="left">
Appointment Summary:</td>
</tr>
<tr>
<td colspan="3">
<asp:TextBox ID="txtEventSummary" runat="server" Width="98%"
Rows="5"></asp:TextBox></td>
</tr>
<tr>
<td align="left">
Appointment Description:</td>
</tr>
<tr>
<td colspan="3">
<asp:TextBox ID="txtEventDescription" runat="server" Rows="5"
Width="98%"></asp:TextBox></td>
</tr>
<tr>
<td align="left">
Starting Date/Time:</td>
<td style="width: 30px" valign="top"></td>
<td align="left" valign="top">Ending Date/Time:</td>
</tr>
<tr>
<td>
<asp:DropDownList ID="ddlStartTime" runat="server"
Width="49%">
<asp:ListItem Value="000000">12:00 AM</asp:ListItem>
<asp:ListItem Value="003000">12:30 AM</asp:ListItem>
<asp:ListItem Value="010000">1:00 AM</asp:ListItem>
<asp:ListItem Value="013000">1:30 AM</asp:ListItem>
<asp:ListItem Value="020000">2:00 AM</asp:ListItem>
<asp:ListItem Value="023000">2:30 AM</asp:ListItem>
<asp:ListItem Value="030000">3:00 AM</asp:ListItem>
<asp:ListItem Value="033000">3:30 AM</asp:ListItem>
<asp:ListItem Value="040000">4:00 AM</asp:ListItem>
<asp:ListItem Value="043000">4:30 AM</asp:ListItem>
<asp:ListItem Value="050000">5:00 AM</asp:ListItem>
<asp:ListItem Value="053000">5:30 AM</asp:ListItem>
<asp:ListItem Value="060000">6:00 AM</asp:ListItem>
<asp:ListItem Value="063000">6:30 AM</asp:ListItem>
<asp:ListItem Value="070000">7:00 AM</asp:ListItem>
<asp:ListItem Value="073000">7:30 AM</asp:ListItem>
<asp:ListItem Value="080000">8:00 AM</asp:ListItem>
<asp:ListItem Value="083000">8:30 AM</asp:ListItem>
<asp:ListItem Value="090000">9:00 AM</asp:ListItem>
<asp:ListItem Value="093000">9:30 AM</asp:ListItem>
<asp:ListItem Value="100000">10:00 AM</asp:ListItem>
<asp:ListItem Value="103000">10:30 AM</asp:ListItem>
<asp:ListItem Value="110000">11:00 AM</asp:ListItem>
<asp:ListItem Value="113000">11:30 AM</asp:ListItem>
<asp:ListItem Value="120000">12:00 PM</asp:ListItem>
<asp:ListItem Value="123000">12:30 PM</asp:ListItem>
<asp:ListItem Value="130000">1:00 PM</asp:ListItem>
<asp:ListItem Value="133000">1:30 PM</asp:ListItem>
<asp:ListItem Value="140000">2:00 PM</asp:ListItem>
<asp:ListItem Value="143000">2:30 PM</asp:ListItem>
<asp:ListItem Value="150000">3:00 PM</asp:ListItem>
<asp:ListItem Value="153000">3:30 PM</asp:ListItem>
<asp:ListItem Value="160000">4:00 PM</asp:ListItem>
<asp:ListItem Value="163000">4:30 PM</asp:ListItem>
<asp:ListItem Value="170000">5:00 PM</asp:ListItem>
<asp:ListItem Value="173000">5:30 PM</asp:ListItem>
<asp:ListItem Value="180000">6:00 PM</asp:ListItem>
<asp:ListItem Value="183000">6:30 PM</asp:ListItem>
<asp:ListItem Value="190000">7:00 PM</asp:ListItem>
<asp:ListItem Value="193000">7;30 PM</asp:ListItem>
<asp:ListItem Value="200000">8:00 PM</asp:ListItem>
<asp:ListItem Value="203000">8:30 PM</asp:ListItem>
<asp:ListItem Value="210000">9:00 PM</asp:ListItem>
<asp:ListItem Value="213000">9:30 PM</asp:ListItem>
<asp:ListItem Value="220000">10:00 PM</asp:ListItem>
<asp:ListItem Value="223000">10:30 PM</asp:ListItem>
<asp:ListItem Value="230000">11:00 PM</asp:ListItem>
<asp:ListItem Value="233000">11:30 PM</asp:ListItem>
</asp:DropDownList><asp:DropDownList ID="ddlStartTZ"
runat="server" Width="50%">
<asp:ListItem>US/Eastern</asp:ListItem>
<asp:ListItem>US/Central</asp:ListItem>
<asp:ListItem>US/Mountain</asp:ListItem>
<asp:ListItem>US/Pacific</asp:ListItem>
</asp:DropDownList></td>
<td style="width: 30px" valign="top"></td>
<td valign="top">
<asp:DropDownList ID="ddlEndTime" runat="server" Width="49%">
<asp:ListItem Value="000000">12:00 AM</asp:ListItem>
<asp:ListItem Value="003000">12:30 AM</asp:ListItem>
<asp:ListItem Value="010000">1:00 AM</asp:ListItem>
<asp:ListItem Value="013000">1:30 AM</asp:ListItem>
<asp:ListItem Value="020000">2:00 AM</asp:ListItem>
<asp:ListItem Value="023000">2:30 AM</asp:ListItem>
<asp:ListItem Value="030000">3:00 AM</asp:ListItem>
<asp:ListItem Value="033000">3:30 AM</asp:ListItem>
<asp:ListItem Value="040000">4:00 AM</asp:ListItem>
<asp:ListItem Value="043000">4:30 AM</asp:ListItem>
<asp:ListItem Value="050000">5:00 AM</asp:ListItem>
<asp:ListItem Value="053000">5:30 AM</asp:ListItem>
<asp:ListItem Value="060000">6:00 AM</asp:ListItem>
<asp:ListItem Value="063000">6:30 AM</asp:ListItem>
<asp:ListItem Value="070000">7:00 AM</asp:ListItem>
<asp:ListItem Value="073000">7:30 AM</asp:ListItem>
<asp:ListItem Value="080000">8:00 AM</asp:ListItem>
<asp:ListItem Value="083000">8:30 AM</asp:ListItem>
<asp:ListItem Value="090000">9:00 AM</asp:ListItem>
<asp:ListItem Value="093000">9:30 AM</asp:ListItem>
<asp:ListItem Value="100000">10:00 AM</asp:ListItem>
<asp:ListItem Value="103000">10:30 AM</asp:ListItem>
<asp:ListItem Value="110000">11:00 AM</asp:ListItem>
<asp:ListItem Value="113000">11:30 AM</asp:ListItem>
<asp:ListItem Value="120000">12:00 PM</asp:ListItem>
<asp:ListItem Value="123000">12:30 PM</asp:ListItem>
<asp:ListItem Value="130000">1:00 PM</asp:ListItem>
<asp:ListItem Value="133000">1:30 PM</asp:ListItem>
<asp:ListItem Value="140000">2:00 PM</asp:ListItem>
<asp:ListItem Value="143000">2:30 PM</asp:ListItem>
<asp:ListItem Value="150000">3:00 PM</asp:ListItem>
<asp:ListItem Value="153000">3:30 PM</asp:ListItem>
<asp:ListItem Value="160000">4:00 PM</asp:ListItem>
<asp:ListItem Value="163000">4:30 PM</asp:ListItem>
<asp:ListItem Value="170000">5:00 PM</asp:ListItem>
<asp:ListItem Value="173000">5:30 PM</asp:ListItem>
<asp:ListItem Value="180000">6:00 PM</asp:ListItem>
<asp:ListItem Value="183000">6:30 PM</asp:ListItem>
<asp:ListItem Value="190000">7:00 PM</asp:ListItem>
<asp:ListItem Value="193000">7;30 PM</asp:ListItem>
<asp:ListItem Value="200000">8:00 PM</asp:ListItem>
<asp:ListItem Value="203000">8:30 PM</asp:ListItem>
<asp:ListItem Value="210000">9:00 PM</asp:ListItem>
<asp:ListItem Value="213000">9:30 PM</asp:ListItem>
<asp:ListItem Value="220000">10:00 PM</asp:ListItem>
<asp:ListItem Value="223000">10:30 PM</asp:ListItem>
<asp:ListItem Value="230000">11:00 PM</asp:ListItem>
<asp:ListItem Value="233000">11:30 PM</asp:ListItem>
</asp:DropDownList><asp:DropDownList ID="ddlEndTZ"
runat="server" Width="50%">
<asp:ListItem>US/Eastern</asp:ListItem>
<asp:ListItem>US/Central</asp:ListItem>
<asp:ListItem>US/Mountain</asp:ListItem>
<asp:ListItem>US/Pacific</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td>
<asp:Calendar ID="calStartDate" runat="server"
BackColor="White" BorderColor="Black" BorderStyle="Solid"
CellSpacing="1" Font-Names="Verdana" Font-Size="9pt"
ForeColor="Black" Height="250px" NextPrevFormat="ShortMonth">
<SelectedDayStyle BackColor="333399" ForeColor="White" />
<TodayDayStyle BackColor="999999" ForeColor="White" />
<DayStyle BackColor="CCCCCC" />
<OtherMonthDayStyle ForeColor="999999" />
<NextPrevStyle Font-Bold="True" Font-Size="8pt"
ForeColor="White" />
<DayHeaderStyle Font-Bold="True" Font-Size="8pt"
ForeColor="333333" Height="8pt" />
<TitleStyle BackColor="333399" BorderStyle="Solid"
Font-Bold="True" Font-Size="12pt"
ForeColor="White" Height="12pt" />
</asp:Calendar>
</td>
<td style="width: 30px" valign="top"></td>
<td valign="top">
<asp:Calendar ID="calEndDate" runat="server"
BackColor="White" BorderColor="Black" BorderStyle="Solid"
CellSpacing="1" Font-Names="Verdana" Font-Size="9pt"
ForeColor="Black" Height="250px" NextPrevFormat="ShortMonth">
<SelectedDayStyle BackColor="333399" ForeColor="White" />
<TodayDayStyle BackColor="999999" ForeColor="White" />
<DayStyle BackColor="CCCCCC" />
<OtherMonthDayStyle ForeColor="999999" />
<NextPrevStyle Font-Bold="True" Font-Size="8pt"
ForeColor="White" />
<DayHeaderStyle Font-Bold="True" Font-Size="8pt"
ForeColor="333333" Height="8pt" />
<TitleStyle BackColor="333399" BorderStyle="Solid"
Font-Bold="True" Font-Size="12pt"
ForeColor="White" Height="12pt" />
</asp:Calendar>
</td>
</tr>
<tr>
<td align="center" colspan="3" valign="top">
<asp:Button ID="btnAddEvent" runat="server"
OnClick="btnAddEvent_Click" Text="Add Event" /></td>
</tr>
</table>
</div>
</form>
Figure 1. Calendar Event Properties Web Form
Implementing the Internet Calendar Event Creation or Sending Functionality
To set the initially selected date on the Web form's calendar controls to the current date, open the Default.aspx.cs or Default.aspx.vb code file and add code to the Page_Load event handler.
![]() |
---|
Default.aspx.cs contains a Page_Load event handler, but Default.aspx.vb does not. To add the Page_Load event handler to Default.aspx.vb, in the class list, under the node for the Web form class name, click the (Page Events) category. Then, click the Load event in the Events list, as shown in Figure 2. |
Figure 2. Adding the Page_Load event handler
To set the selected date on the Web form
- Add the following code to the body of the Page_Load event handler.
If Not IsPostBack Then
Dim dtNow As DateTime = _
DateTime.Parse(DateTime.Now.ToShortDateString())
calStartDate.SelectedDate = dtNow
calEndDate.SelectedDate = dtNow
End If
if (!IsPostBack)
{
DateTime dtNow = DateTime.Parse(DateTime.Now.ToShortDateString());
calStartDate.SelectedDate = dtNow;
calEndDate.SelectedDate = dtNow;
}
To create an Internet Calendar
Add the following code to the Default.aspx.cs or Default.aspx.vb code file, inside the class definition for the page and after the Page_Load event handler.
The code uses the values specified on the Web form for the calendar appointment properties to create a string representing an Internet Calendar .ics file. It then writes the string to the response stream, specifying a content type of text/calendar. This launches Microsoft Outlook on the client, displays the calendar appointment's details, and gives the user the option of adding the appointment to an Outlook calendar.
Protected Sub btnAddEvent_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles btnAddEvent.Click
Dim sbICSFile As StringBuilder = New StringBuilder()
Dim dtNow As DateTime = DateTime.Now
sbICSFile.AppendLine("BEGIN:VCALENDAR")
sbICSFile.AppendLine("VERSION:2.0")
sbICSFile.AppendLine("PRODID:-//AkonaDev/CalendarAppointment")
sbICSFile.AppendLine("CALSCALE:GREGORIAN")
sbICSFile.AppendLine("BEGIN:VEVENT")
' Define time zones.
' US/Eastern
sbICSFile.AppendLine("BEGIN:VTIMEZONE")
sbICSFile.AppendLine("TZID:US/Eastern")
sbICSFile.AppendLine("BEGIN:STANDARD")
sbICSFile.AppendLine("DTSTART:20071104T020000")
sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11")
sbICSFile.AppendLine("TZOFFSETFROM:-0400")
sbICSFile.AppendLine("TZOFFSETTO:-0500")
sbICSFile.AppendLine("TZNAME:EST")
sbICSFile.AppendLine("END:STANDARD")
sbICSFile.AppendLine("BEGIN:DAYLIGHT")
sbICSFile.AppendLine("DTSTART:20070311T020000")
sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3")
sbICSFile.AppendLine("TZOFFSETFROM:-0500")
sbICSFile.AppendLine("TZOFFSETTO:-0400")
sbICSFile.AppendLine("TZNAME:EDT")
sbICSFile.AppendLine("END:DAYLIGHT")
sbICSFile.AppendLine("END:VTIMEZONE")
' US/Central
sbICSFile.AppendLine("BEGIN:VTIMEZONE")
sbICSFile.AppendLine("TZID:US/Central")
sbICSFile.AppendLine("BEGIN:STANDARD")
sbICSFile.AppendLine("DTSTART:20071104T020000")
sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11")
sbICSFile.AppendLine("TZOFFSETFROM:-0500")
sbICSFile.AppendLine("TZOFFSETTO:-0600")
sbICSFile.AppendLine("TZNAME:CST")
sbICSFile.AppendLine("END:STANDARD")
sbICSFile.AppendLine("BEGIN:DAYLIGHT")
sbICSFile.AppendLine("DTSTART:20070311T020000")
sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3")
sbICSFile.AppendLine("TZOFFSETFROM:-0600")
sbICSFile.AppendLine("TZOFFSETTO:-0500")
sbICSFile.AppendLine("TZNAME:CDT")
sbICSFile.AppendLine("END:DAYLIGHT")
sbICSFile.AppendLine("END:VTIMEZONE")
' US/Mountain
sbICSFile.AppendLine("BEGIN:VTIMEZONE")
sbICSFile.AppendLine("TZID:US/Mountain")
sbICSFile.AppendLine("BEGIN:STANDARD")
sbICSFile.AppendLine("DTSTART:20071104T020000")
sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11")
sbICSFile.AppendLine("TZOFFSETFROM:-0600")
sbICSFile.AppendLine("TZOFFSETTO:-0700")
sbICSFile.AppendLine("TZNAME:MST")
sbICSFile.AppendLine("END:STANDARD")
sbICSFile.AppendLine("BEGIN:DAYLIGHT")
sbICSFile.AppendLine("DTSTART:20070311T020000")
sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3")
sbICSFile.AppendLine("TZOFFSETFROM:-0700")
sbICSFile.AppendLine("TZOFFSETTO:-0600")
sbICSFile.AppendLine("TZNAME:MDT")
sbICSFile.AppendLine("END:DAYLIGHT")
sbICSFile.AppendLine("END:VTIMEZONE")
' US/Pacific
sbICSFile.AppendLine("BEGIN:VTIMEZONE")
sbICSFile.AppendLine("TZID:US/Pacific")
sbICSFile.AppendLine("BEGIN:STANDARD")
sbICSFile.AppendLine("DTSTART:20071104T020000")
sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11")
sbICSFile.AppendLine("TZOFFSETFROM:-0700")
sbICSFile.AppendLine("TZOFFSETTO:-0800")
sbICSFile.AppendLine("TZNAME:PST")
sbICSFile.AppendLine("END:STANDARD")
sbICSFile.AppendLine("BEGIN:DAYLIGHT")
sbICSFile.AppendLine("DTSTART:20070311T020000")
sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3")
sbICSFile.AppendLine("TZOFFSETFROM:-0800")
sbICSFile.AppendLine("TZOFFSETTO:-0700")
sbICSFile.AppendLine("TZNAME:PDT")
sbICSFile.AppendLine("END:DAYLIGHT")
sbICSFile.AppendLine("END:VTIMEZONE")
' Define the event
sbICSFile.Append("DTSTART;TZID=" + ddlStartTZ.Text + ":")
sbICSFile.Append(calStartDate.SelectedDate.Year.ToString())
sbICSFile.Append( _
FormatDateTimeValue(calStartDate.SelectedDate.Month))
sbICSFile.Append( _
FormatDateTimeValue(calStartDate.SelectedDate.Day) + "T")
sbICSFile.AppendLine(ddlStartTime.SelectedValue)
sbICSFile.Append("DTEND;TZID=" + ddlEndTZ.Text + ":")
sbICSFile.Append(calEndDate.SelectedDate.Year)
sbICSFile.Append( _
FormatDateTimeValue(calEndDate.SelectedDate.Month))
sbICSFile.Append( _
FormatDateTimeValue(calEndDate.SelectedDate.Day) + "T")
sbICSFile.AppendLine(ddlEndTime.SelectedValue)
sbICSFile.AppendLine("SUMMARY:" + txtEventSummary.Text)
sbICSFile.AppendLine("DESCRIPTION:" + txtEventDescription.Text)
sbICSFile.AppendLine("UID:1")
sbICSFile.AppendLine("SEQUENCE:0")
sbICSFile.Append("DTSTAMP:" + dtNow.Year.ToString())
sbICSFile.Append(FormatDateTimeValue(dtNow.Month))
sbICSFile.Append(FormatDateTimeValue(dtNow.Day) + "T")
sbICSFile.Append(FormatDateTimeValue(dtNow.Hour))
sbICSFile.AppendLine(FormatDateTimeValue(dtNow.Minute) + "00")
sbICSFile.AppendLine("END:VEVENT")
sbICSFile.AppendLine("END:VCALENDAR")
Response.ContentType = "text/calendar"
Response.AddHeader("content-disposition", _
"attachment; filename=CalendarEvent1.ics")
Response.Write(sbICSFile)
Response.End()
End Sub
protected function FormatDateTimeValue(DateValue as Int16) as string
If DateValue < 10 Then
Return "0" + DateValue.ToString()
Else
Return DateValue.ToString()
End If
End Function
protected void btnAddEvent_Click(object sender, EventArgs e)
{
System.Text.StringBuilder sbICSFile =
new System.Text.StringBuilder();
DateTime dtNow = DateTime.Now;
sbICSFile.AppendLine("BEGIN:VCALENDAR");
sbICSFile.AppendLine("VERSION:2.0");
sbICSFile.AppendLine("PRODID:-//ICSTestCS/");
sbICSFile.AppendLine("CALSCALE:GREGORIAN");
// Define time zones.
// US/Eastern
sbICSFile.AppendLine("BEGIN:VTIMEZONE");
sbICSFile.AppendLine("TZID:US/Eastern");
sbICSFile.AppendLine("BEGIN:STANDARD");
sbICSFile.AppendLine("DTSTART:20071104T020000");
sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11");
sbICSFile.AppendLine("TZOFFSETFROM:-0400");
sbICSFile.AppendLine("TZOFFSETTO:-0500");
sbICSFile.AppendLine("TZNAME:EST");
sbICSFile.AppendLine("END:STANDARD");
sbICSFile.AppendLine("BEGIN:DAYLIGHT");
sbICSFile.AppendLine("DTSTART:20070311T020000");
sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3");
sbICSFile.AppendLine("TZOFFSETFROM:-0500");
sbICSFile.AppendLine("TZOFFSETTO:-0400");
sbICSFile.AppendLine("TZNAME:EDT");
sbICSFile.AppendLine("END:DAYLIGHT");
sbICSFile.AppendLine("END:VTIMEZONE");
// US/Central
sbICSFile.AppendLine("BEGIN:VTIMEZONE");
sbICSFile.AppendLine("TZID:US/Central");
sbICSFile.AppendLine("BEGIN:STANDARD");
sbICSFile.AppendLine("DTSTART:20071104T020000");
sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11");
sbICSFile.AppendLine("TZOFFSETFROM:-0500");
sbICSFile.AppendLine("TZOFFSETTO:-0600");
sbICSFile.AppendLine("TZNAME:CST");
sbICSFile.AppendLine("END:STANDARD");
sbICSFile.AppendLine("BEGIN:DAYLIGHT");
sbICSFile.AppendLine("DTSTART:20070311T020000");
sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3");
sbICSFile.AppendLine("TZOFFSETFROM:-0600");
sbICSFile.AppendLine("TZOFFSETTO:-0500");
sbICSFile.AppendLine("TZNAME:CDT");
sbICSFile.AppendLine("END:DAYLIGHT");
sbICSFile.AppendLine("END:VTIMEZONE");
// US/Mountain
sbICSFile.AppendLine("BEGIN:VTIMEZONE");
sbICSFile.AppendLine("TZID:US/Mountain");
sbICSFile.AppendLine("BEGIN:STANDARD");
sbICSFile.AppendLine("DTSTART:20071104T020000");
sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11");
sbICSFile.AppendLine("TZOFFSETFROM:-0600");
sbICSFile.AppendLine("TZOFFSETTO:-0700");
sbICSFile.AppendLine("TZNAME:MST");
sbICSFile.AppendLine("END:STANDARD");
sbICSFile.AppendLine("BEGIN:DAYLIGHT");
sbICSFile.AppendLine("DTSTART:20070311T020000");
sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3");
sbICSFile.AppendLine("TZOFFSETFROM:-0700");
sbICSFile.AppendLine("TZOFFSETTO:-0600");
sbICSFile.AppendLine("TZNAME:MDT");
sbICSFile.AppendLine("END:DAYLIGHT");
sbICSFile.AppendLine("END:VTIMEZONE");
// US/Pacific
sbICSFile.AppendLine("BEGIN:VTIMEZONE");
sbICSFile.AppendLine("TZID:US/Pacific");
sbICSFile.AppendLine("BEGIN:STANDARD");
sbICSFile.AppendLine("DTSTART:20071104T020000");
sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11");
sbICSFile.AppendLine("TZOFFSETFROM:-0700");
sbICSFile.AppendLine("TZOFFSETTO:-0800");
sbICSFile.AppendLine("TZNAME:PST");
sbICSFile.AppendLine("END:STANDARD");
sbICSFile.AppendLine("BEGIN:DAYLIGHT");
sbICSFile.AppendLine("DTSTART:20070311T020000");
sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3");
sbICSFile.AppendLine("TZOFFSETFROM:-0800");
sbICSFile.AppendLine("TZOFFSETTO:-0700");
sbICSFile.AppendLine("TZNAME:PDT");
sbICSFile.AppendLine("END:DAYLIGHT");
sbICSFile.AppendLine("END:VTIMEZONE");
// Define the event.
sbICSFile.AppendLine("BEGIN:VEVENT");
sbICSFile.Append("DTSTART;TZID=" + ddlStartTZ.Text + ":");
sbICSFile.Append(calStartDate.SelectedDate.Year.ToString());
sbICSFile.Append(
FormatDateTimeValue(calStartDate.SelectedDate.Month));
sbICSFile.Append(
FormatDateTimeValue(calStartDate.SelectedDate.Day) + "T");
sbICSFile.AppendLine(ddlStartTime.SelectedValue);
sbICSFile.Append("DTEND;TZID=" + ddlEndTZ.Text + ":");
sbICSFile.Append(calEndDate.SelectedDate.Year);
sbICSFile.Append(
FormatDateTimeValue(calEndDate.SelectedDate.Month));
sbICSFile.Append(
FormatDateTimeValue(calEndDate.SelectedDate.Day) + "T");
sbICSFile.AppendLine(ddlEndTime.SelectedValue);
sbICSFile.AppendLine("SUMMARY:" + txtEventSummary.Text);
sbICSFile.AppendLine("DESCRIPTION:" + txtEventDescription.Text);
sbICSFile.AppendLine("UID:1");
sbICSFile.AppendLine("SEQUENCE:0");
sbICSFile.Append("DTSTAMP:" + dtNow.Year.ToString());
sbICSFile.Append(FormatDateTimeValue(dtNow.Month));
sbICSFile.Append(FormatDateTimeValue(dtNow.Day) + "T");
sbICSFile.Append(FormatDateTimeValue(dtNow.Hour));
sbICSFile.AppendLine(FormatDateTimeValue(dtNow.Minute) + "00");
sbICSFile.AppendLine("END:VEVENT");
sbICSFile.AppendLine("END:VCALENDAR");
Response.ContentType = "text/calendar";
Response.AddHeader("content-disposition",
"attachment; filename=CalendarEvent1.ics");
Response.Write(sbICSFile);
Response.End();
}
private string FormatDateTimeValue(int DateValue)
{
if (DateValue < 10)
return "0" + DateValue.ToString();
else
return DateValue.ToString();
}
Read It
This article explores how to send Internet Calendar appointments from an ASP.NET 2.0 Web site to Microsoft Office Outlook 2007. The key steps include:
Creating an ASP.NET 2.0 Web Site project in Visual Studio 2005.
Creating a Web form for the site that lets a user specify a summary, description, and start or end dates and times for a calendar appointment.
Adding code to the Web form's code file that implements the Internet Calendar appointment creation and sending functionality.