SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software Kodyaz Development Resources
Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Vista, etc.






.NET Framework, ASP.NET

ASP.NET, Windows Forms, Controls, .NET Framework and Visual Studio Articles

ASP.NET Forums

Visual Studio Forums

.NET Development Blog

Certification Exams Blog




Sample ASP.NET Web Application for Creating Outlook Appointments on the Fly and Send as e-Mail Attachment or Download as Files in .vcs or .ics Formats


I have developed a sample web application in order to create MS Outlook Appointment and send the appointment request as an email attachment to the receivers.
After struggling with all the points I should overcome using small tips and tricks, sending a meeting request or sending an appointment request from ASP.NET web application has never been so easy for me :)
If you are a developer or a programmer and reading this article, I hope you will find the clues and code blocks you will need to use in your programs or codes.

This article can be assumed as a step by step tutorial which may guide you to create, download or send an appointment request as a email attachment.
You can find the download of the sample web application source codes at the bottom of the tutorial.
You can download free and run the sample ASP.NET web site application to test whether it will fullfil your requirements.
Feel free to alter the source codes in order to customize the ASP.NET application according to your business requirements.
The VB.NET source codes of the ASP.NET application can be used as base methods and samples for creating similar Windows Form applications.

This is as single page web application which has a user interface where you can select to create the Outlook Appointment and download the appointment file as .vcs or .ics file formats or you can select to send the appointment request as an e-mail attachment file.
The web user interface has also a calendar and a time picker for both start date and end date parameters of the appointment.
I have also added three textbox, each texbox is used for to enter the Location, Subject and the Description of the Appointment.
A dropdownlist ASP.NET web control is added to hold the values for the Priority of the Appointment.
There exists also input controls for e-mail address and display name for the email in order to use with the send appointment as e-mail attachment scenario case.

Sample ASP.NET web application for creating Outlook appointments on the fly and send as e-mail attachment or download as .vcs or .ics file

While programming the ASP.NET web site, I had faced a few problems to solve. First of all I have checked the file format of an Outlook Appointment record. You know you can save an Outlook appointment or a meeting request by opening the item on the Calendar tab by a double-click. And save the appointment record from the File, Save As menu item in the iCalendar Format (.ics) to your computer disk and open it using a text editor like Notepad for example.

appointment iCalendar file format

Sample Appointment File in iCalendar .ics or in vcs Formats


You can find below the text contents of a sample appointment file saved as iCalendar file.

BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
ORGANIZER:MAILTO:eralper@nosuchemail.com
DTSTART:20090306T140000Z
DTEND:20090306T150000Z
LOCATION:Meeting Room 1-D
TRANSP:OPAQUE
SEQUENCE:0
UID:040000008200E00074C5B7101A82E00800000000B09916C3F9ADC9010000000000000000100
0000099DFBC4731297248A2CAF0885C8C4856
DTSTAMP:20090326T080109Z
DESCRIPTION:A short discussion on topics related with upgrade of HiPath
ProCenter SDK Applications\n
SUMMARY:Upgrade HiPath ProCenter SDK Applications
PRIORITY:5
X-MICROSOFT-CDO-IMPORTANCE:1
CLASS:PUBLIC
BEGIN:VALARM
TRIGGER:-PT15M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
END:VCALENDAR

What is important in this format is the DTSTART and DTEND, LOCATION, DESCRIPTION, SUMMARY and PRIORITY maybe.
So I have simplified in my ASP.NET codes to gather only these data and build an appointment file only including these data.
I developed and code for creating an appointment .vcs file like below :

BEGIN: VCALENDAR
BEGIN: VEVENT
DTSTART:20090326T064500Z
DTEND:20090326T064500Z
LOCATION;ENCODING=QUOTED-PRINTABLE:Meeting Room 1-D
UID: FD7D9F229CAE422AA76738B77044DA9659A83
DESCRIPTION;ENCODING=QUOTED-PRINTABLE:Short discussion on Code Upgrade
SUMMARY;ENCODING=QUOTED-PRINTABLE:Upgrade HiPath ProCenter SDK Applications
PRIORITY:1
End : VEVENT
End : VCALENDAR

I have prepared and formed the text content of the file using a StringBuilder object in the method BuildVCSFile() where you can find in the code behind file vcs.aspx.vb

One important problem that I had to solve during the programming was encoding the string input values using the Quoted-Printable Encoding.
I'll try to explain how I found a solution for encoding text using the quoted printable encoding in the following sub-titles.


ASP.NET Calendar and Time Picker (Time Selector) Controls

I have used standart ASP.NET Calendar control for as an input interface for DTSTART and DTEND date values.
I preferred a third party control for selecting time intervals. I have placed two time picker control onto the aspx web page.
I chosed ASP.NET Time Picker Control from Michael Bell. You can review to ASP.NET Control Gallery for more information and sample source codes on the ASP.NET Time Picker Control.
Michael has created a timeselector control which you would love it I believe. I can suggest you check his site http://www.michaelkbell.com/.

Custom ASP.NET Time Picker Control


Encoding and Decoding using Quoted-Printable Encoding

In the .vcs or .ics file, the Description, Summary, Location, etc fields may be including special characters (non-standart or unicode characters) that without encoding or decoding correctly these free-text fields may display incorrect or corrupt characters on the appointment or on the event record.
So if you are working with such an alphabet that you should treat carefully then as a developer you should convert the input characters using quoted-printable encoding.
This was one of the main obstacle that has slowed me during coding the web application.
How can I or encode a string using quoted printable encoding or decode a quoted-printable encoded string ?

I have made some Google search for a while and I preferred to use third party .NET code libraries for dealing with quoted-printable encoding system.
I downloaded the Chilkat .NET Components and added this library as a reference to my ASP.NET project. I actually added the .dll file ChilkatDotNet2.dll into the Bin folder.
After adding the magic library as a reference to the project, I have adopted the sample code for Quoted-Printable Encoding and Decoding from Quoted-Printable Sample page.
Again if you download and review the source codes of the sample projecti you will see that I have implemented two methods QuotedPrintableEncodeString() and QuotedPrintableDecodeString() for encoding and decoding text in order to use during creation of Outlook appointment request record.


Downloading .vcs Appointment File from an ASP.NET Web Page

During your review of the source code of the sample web application, you will see the DownloadAsVCS() method.
DownloadAsVCS() method is used for sending the response hich is forming the content of the .vcs file to the client.
So when the user on the client side selects to download the request as .vcs file the DownloadAsVCS() method is used to stream the content to the web client as a downloadable file.
What is important to take care in this method is the following code statements.

Response.ContentType = "text/calendar"
Response.AddHeader("Content-disposition", "filename=AppointmentRequest.vcs")

How to Create Appointment File as an E-Mail Attachment

Another step to solve creating appointment file is creating a file attachment from string values we have formed using the input via user interface.
If you look at the constructors of System.Net.Mail 's Attachment class, there exists a method which takes a System.IO.MemoryStream object as an input parameter.
This content stream parameter contains the contents of the desired appointment request attachment.
And definitely this MemoryStream type content stream object contains the output of the BuildVCSFile() method included in the sample free downloadable project.

So I had developed a small code block that converts a text or a string object into a memorystream object.
To manage this task, first text is converted into a bytes array representation using GetBytes() method of the Encoding class in System.Text namespace.
Then I used the Write() method of the MemoryStream object in order to stream the contents of the byte array into the MemoryStream object.

How to Convert String into MemoryStream object


Dim strInBytes As Byte() = Encoding.UTF8.GetBytes(text)
Dim _MemoryStream As MemoryStream = New MemoryStream()
_MemoryStream.Write(strInBytes, 0, strInBytes.Length) _MemoryStream.Seek(0, SeekOrigin.Begin)
Dim attachment As Attachment = New Attachment(_MemoryStream, "Appointment.vcs")

Download Sample ASP.NET Web Site Project with Source Code

You can free download the source code of the ASP.NET Web Site project which I have developed using VB.NET using Microsoft Visual Studio 2008 from ASP.NET Source Codes for Creating, Downloading and Sending Appointment File as e-Mail Attachment.






Follow Kodyaz on Twitter








Copyright © 2004 - 2014 Eralper Yilmaz. All rights reserved.
Community Server by Telligent Systems