IntroductionNow a day’s event management is becoming a very popular idea especially in case of web application development. Most of the application is synchronizing with outlook contacts and calendar. Here is a small tool to create event both hour event and day event. This concept is very simple creating a ics file and sending as mail attachment. Implementation I was developing a web application which is related to event management and my client requirement is to send day and hour event so it will be synchronized with client’s outlook calendar. Send Event/AppointmentIn outlook two type of event/appointment can be sent. 1. Hourly event (based on specific hour of a day) 2. Day event (based on specific days) To send hourly event need to send ics file for hour event ics file look like that I have made a simple UI to send hour event. To load hour use a simple control from AjaxControlToolkit. this is the simple UI. Code to create ics file for day event/appointmentpublic string MakeHourEvent(string subject, string location, DateTime date, string startTime, string endTime)
{
string filePath = string.Empty;
string path = HttpContext.Current.Server.MapPath(@"\iCal\");
filePath = path + subject + ".ics";
writer = new StreamWriter(filePath);
writer.WriteLine("BEGIN:VCALENDAR");
writer.WriteLine("VERSION:2.0");
writer.WriteLine("PRODID:-//hacksw/handcal//NONSGML v1.0//EN");
writer.WriteLine("BEGIN:VEVENT");
string startDateTime = GetFormatedDate(date)+"T"+GetFormattedTime(startTime);
string endDateTime = GetFormatedDate(date) + "T" + GetFormattedTime(endTime);
writer.WriteLine("DTSTART:" + startDateTime);
writer.WriteLine("DTEND:" + endDateTime);
writer.WriteLine("SUMMARY:" + subject);
writer.WriteLine("LOCATION:" + location);
writer.WriteLine("END:VEVENT");
writer.WriteLine("END:VCALENDAR");
writer.Close();
return filePath;
} To send daily event need to send ics file this file look like that
I have made a simple UI using an Ajaxtoolkit CalendarExtender. Here user can select different date from calendar and in case of day event creation no need to ecter time. Here are the codes to create day eventpublic string MakeDayEvent(string subject, string location, DateTime startDate, DateTime endDate)
{
string filePath = string.Empty;
string path = HttpContext.Current.Server.MapPath(@"\iCal\");
filePath = path + subject + ".ics";
writer = new StreamWriter(filePath);
writer.WriteLine("BEGIN:VCALENDAR");
writer.WriteLine("VERSION:2.0");
writer.WriteLine("PRODID:-//hacksw/handcal//NONSGML v1.0//EN");
writer.WriteLine("BEGIN:VEVENT");
string startDay = "VALUE=DATE:" + GetFormatedDate(startDate);
string endDay = "VALUE=DATE:" + GetFormatedDate(endDate);
writer.WriteLine("DTSTART;" + startDay);
writer.WriteLine("DTEND;" + endDay);
writer.WriteLine("SUMMARY:" + subject);
writer.WriteLine("LOCATION:" + location);
writer.WriteLine("END:VEVENT");
writer.WriteLine("END:VCALENDAR");
writer.Close();
return filePath;
}Code to send mail with attachementpublic void SendMail(string from, string to, string subject, string body, Attachment attachment)
{
MailMessage mail = new MailMessage(from, to, subject, body);
mail.Attachments.Add(attachment);
SmtpClient smtp = new SmtpClient("localhost");
smtp.Send(mail);
mail.Dispose();
}ConclusionIn this article i have given detail to send appointment through the email in ASP.NET. thank yo for reading. Sample Project SourceDownload source files -780 kb |