# Sunday, 08 January 2012

If you provide a way for your user to make an appointment it’s always a good idea to provide a reminder mechanism for him or her. A nice way to do this is to send a mail. But a mail alone is sometimes not enough and Microsoft Outlook users for example would rather love to see a .ics appointment attached.

The System.Net.Mail namespace provides the needed functionality to get this recipe cooking in no time and will taste great afterwards.

First part of the recipe are the helper classes which hold the functionality for making up the ics content and sending a mail depending on provided input.

The Mailing class:

using System.Net.Mail;
using System.Web.Configuration;

namespace IcsAsMailAttachment.Controllers
    public class Mailing
        public void SendMail(string from, string to, string subject, string body, Attachment attachment)
            using (MailMessage mailClient = new MailMessage(from, to, subject, body))
                mailClient.IsBodyHtml = true;

                SmtpClient smtp = new SmtpClient(WebConfigurationManager.AppSettings["mailserver"]);


This class does the actual sending. The mailserver, on line 15, is retrieved from the web.config file appSettings section. This makes it easy for the site admin to change the mail server without having to adjust and redeploy the code (saving time and money).

The Appointment class:

using System;
using System.Text;

namespace IcsAsMailAttachment.Controllers
    public class Appointment
        private string GetFormatedDate(DateTime date)
             return string.Format("{0:00}{1:00}{2:00}", date.Year, date.Month, date.Day);

        private string GetFormattedTime(DateTime dateTime)
            return string.Format("T{0:00}{1:00}{2:00}", dateTime.Hour, dateTime.Minute, dateTime.Second);

        public string CreateIcs(string subject, string location, DateTime startDate, DateTime endDate)
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("PRODID:-//hacksw/handcal//NONSGML v1.0//EN");

            string startDay = string.Format("VALUE=DATE:{0}{1}",
                GetFormatedDate(startDate), GetFormattedTime(startDate));

            string endDay = string.Format("VALUE=DATE:{0}{1}", 
                GetFormatedDate(endDate), GetFormattedTime(endDate));

            sb.AppendLine("DTSTART;" + startDay);
            sb.AppendLine("DTEND;" + endDay);
            sb.AppendLine("SUMMARY:" + subject);
            sb.AppendLine("LOCATION:" + location);

            return sb.ToString();

The Appointment class does the heavy lifting of generating the string needed for the ics markup. Two helper methods are put in place to get a nicely formatted Date and Time string.

The SendMailController class:

using System;
using System.IO;
using System.Net.Mail;
using System.Text;
using System.Web.Mvc;

namespace IcsAsMailAttachment.Controllers
    public class SendMailController : Controller
        // GET: /SendMail/

        public ActionResult Index()
            string ics = new Appointment().CreateIcs("A great meeting to attend!", "In the cloud",
                new DateTime(2012, 2, 3, 18, 0, 0), new DateTime(2012, 2, 3, 22, 15, 0));

            MemoryStream ms = new MemoryStream();
            UTF8Encoding enc = new UTF8Encoding();
            byte[] arrBytData = enc.GetBytes(ics);
            ms.Write(arrBytData, 0, arrBytData.Length);
            ms.Position = 0;

            // Be sure to give the name a .ics extension here, otherwise it will not work.
            Attachment attachment = new Attachment(ms, "Appointment.ics");

            new Mailing().SendMail("from@contoso.com", "to@ymca.com", 
                "The subject", "<strong>Welcome to the cloud!</strong>", attachment);

            return View();

The SendMailController class, I tested this in an ASP.NET MVC 3 web application, creates a new ICS appointment on line 16. For being able to send the attachment without first having to save it to disk we create a MemoryStream instance on line 19 and transform our ics to a byte array so that we can pass it along in the constructor of the Attachment class on line 26. The highlight is on line 26 as you will need to provide the .ics extension in the name there.

When testing this you might want to send it directly via a mail server. However this might get the sys admin at your company upset or perhaps gets the sender email address that you use blacklisted. For this purpose you can tell ASP.NET to drop the generated mail on disk instead. Just be sure to turn that off when you are deploying to a live production as otherwise nobody will receive your emails!

Email settings in web.config:

<?xml version="1.0"?>

      <smtp deliveryMethod="SpecifiedPickupDirectory">
        <specifiedPickupDirectory pickupDirectoryLocation="C:\temp\mails" />


The results:

Once the mail has been sent, it will appear in the designated pickup directory location as specified in the web.config.

Pickup folder for ASP.NET mails

Double clicking on the .eml file opens it up in in the associated application, for me that is Outlook.

The email that was sent

There you see the Appointment.ics file. Remember the name we gave on line 26 in the SendMailController? Yes, that is exactly the name, and correct extension, that was provided. Double click the ics file and you can see the appointment.

The ICS file opened ready for adding it to the agenda in Outlook

The date and times come from the parameters passed in the SendMailController class on line 16 and 17.

As you can see, it is quite easy to set this up with just a bit of code. Providing the opportunity to add an appointment directly to the agenda of the interested user is a great benefit. They don’t have to create one themselves, enter in the dates and hours, possibly making mistakes when doing so, … Make it easy for your customers to keep their agenda up to date in a quick and easy way and they’ll love it.

Grz, Kris.

Sunday, 08 January 2012 14:51:10 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [1]  | 
# Wednesday, 04 January 2012

Just noticed via Twitter that there’s a new December 2011 update available: Visual Studio 2010 and .NET Framework 4 Training Kit December 2011 update. This training kit holds a lot of interesting small videos, demos, code, … oh my.

Today I also found out about a blog post that lists around 30 free books. Books about javascript, Ruby, C#, …

Grz, Kris.

Wednesday, 04 January 2012 21:13:49 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Tuesday, 27 December 2011

Today I’ve spent some time on getting the first pages right for a new site. Since 2006 I’ve only had a blog but no particular pages handy on my site. Due to demand by people I decided to take this part up and already crafted several pages:

Today these are still simple html but I want to switch to a full blown CMS system soon. The one that I have in mind is Orchard.

The pages themselves are made up with some small CSS 3 enhancements and HTML 5 semantics in mind. I based it on the Mango theme people can download for Orchard. Actually I started up WebMatrix, grabbed Orchard from the gallery, set up a site and took the aforementioned Mango theme. Then simply creating a couple of pages and in the browser save these as html. Then took Sublime 2 to change some paths to some scripts. Uploaded and voila, one happy camper Smile.

Grz, Kris.

Tuesday, 27 December 2011 22:01:21 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 


recently I gave a WebCamps for Microsoft and for that I created a custom hands on lab about Orchard CMS. I put this online for everyone to enjoy. You can download it here.

Grz, Kris.

Tuesday, 27 December 2011 19:43:51 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Saturday, 24 December 2011

The list of sessions of Techdays 2012 is practically at 100% so that makes it easy to start choosing the ones I would like to attend up front Smile.

My todo list for those days are:

Day 1

Day 2

Grz, Kris.

Saturday, 24 December 2011 22:01:05 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Friday, 23 December 2011

With prices of hard drives going up at the moment you might want to reclaim some valuable space on it.

Web Platform Installer is a great tool to streamline downloads, their dependencies and have these installed on computer. I’m sure you already have this gem installed. If not, then quickly reach out here and grab it: http://www.microsoft.com/web/downloads/platform.aspx. Really, do it now. It’s that cool.

Of course downloading all the cool new tools or updates can start to weigh on that poor little disk inside your pc after a while and you might want to clean up after a while. The steps are pretty easy if you know where to look:

  1. Open Windows Explorer
  2. In the address bar type in the following: %localappdata%\Microsoft\Web Platform Installer
  3. In the Installers subfolder you can find the gold. Either save it on an external hard drive or delete as much as you want.

Grz, Kris.

Friday, 23 December 2011 21:06:13 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Thursday, 22 December 2011

Recently Microsoft released a new web site where you can see what will be covered by

  • Live meetings
  • Offline events
  • Community events

Be sure to check it out at www.msdn-events.be.

Grz, Kris.

Thursday, 22 December 2011 22:24:58 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Wednesday, 14 December 2011

The last months were pretty quiet around ScottGu but yesterday evening, for us Belgian people, there was a great and lengthy streamed event about Windows Azure. As I’m the competence center leader of the Azure Cloud Computing team at Ordina Belgium I took the opportunity to gather up with colleagues, ordered pizza and made a great evening.

I’m glad to see this kind of events happening. They provide excellent coverage about the topic, starting out in a way that newcomers can follow with ease but also introducing the latest and greatest tooling and progress the Windows Azure platform has made during the last months. There’s also a ton of great news on the fronts of having people with skills other than .NET being served as well. Node.js, Java, PHP and other technologies get attention. That’s just awesome!

The Windowsazure.com website also got a major update with that nice looking Metro style sauce over it.

In the past people sometimes feared testing the cloud for budget reasons. Even a colleague of mine once had to find out the hard way that when you shut down an instance but keep the deployment you also keep on getting charged. Microsoft now releases a new way to explore Azure for 3 months but with a spending limit. According to me that promises a safer way to spend researching Azure.

Grz, Kris.

Wednesday, 14 December 2011 14:25:54 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, 12 December 2011

Recently the 1.6 version of the SDK came out and that usually is followed up by a new version of the training toolkit. You can grab the latest version here.

The December 2011 update of the training kit includes the following updates:

  • [New Presentations] 33 updated/new PowerPoint presentations
  • [New Hands-On lab] Running a parametric sweep application with the Windows Azure HPC Scheduler
  • [New Hands-On lab] Running SOA Services with the Windows Azure HPC Scheduler
  • [New Hands-On lab] Running MPI Applications with the Windows Azure HPC Scheduler
  • [New Demo] Node.js On Windows Azure
  • [New Demo] Image Rendering Parametric Sweep Application with the Windows Azure HPC Scheduler
  • [New Demo] BLAST Parametric Sweep Application with the Windows Azure HPC Scheduler
  • [Renamed Lab] Connecting Applications through Windows Azure Service Bus (formerly Introduction to Service Bus Part 1)
  • [Renamed Lab] Windows Azure Service Bus Advanced Configurations (formerly Introduction to Service Bus Part 2)

Grz, Kris.

Monday, 12 December 2011 20:15:22 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, 05 December 2011

Today I gave my first Webcamps session at Microsoft Belgium. The agenda for  the day was

9:00 – 10:30

Web Platform Overview and open source Web Apps

Get a good overview of the Microsoft Web Platform, free tooling like Visual Studio 2010, Web Developer Express, IIS web server and a peek at what’s coming in Visual Studio 11 and ASP.NET MVC 4.

After the general introduction we’ll show you around Orchard CMS, Umbraco and other open source CMS apps using WebMatrix.

10:30 – 11:00

Coffee Break

11:00 – 12:30

Practical HTML5

This session kicks off with a good overview of the different elements in HTML5 that make up this umbrella term. We’ll go over standards HTML, new CSS3 specs and font usage and web app specs. Most importantly, the session will also address how you can start taking advantage of new features in the specs while still supporting older browsers through the use of polyfills and frameworks like Modernizr.

To finish you’ll learn how to make your website shine on the Windows 7 taskbar through site pinning.

12:30 – 13:30


Afternoon – Hands-on labs

13:30 – 17:00

Hands-on labs

The afternoon is hands-on, the perfect timing to apply the learning from the morning session.

Labs include creating a website using a web app by leveraging, practical HTML5 and CSS3 labs addressing Canvas, WOFF, CSS3 layout features and more.

At the end of the session you’ll have a good practical feeling on how to use and customize open source web apps as well as leveraging the best in HTML5 today.

17:00 – 17:15

Closing, discussion, top recommended resources

There were 2 hands on labs foreseen. One recycled from Microsoft Webcamps USA about HTML 5 and another one I completely wrote myself about Orchard and on which I got some great feedback from the people who made it during the afternoon.

About 35 people followed the course and I already got quite some questions after the first session was sold out if there were others going to happen. Luckily I can answer that question in a positive way as the following dates are foreseen for a redelivery:

Even though I got some great feedback in the evaluation round I also want to take the entire feedback with me into my next presentation to perform even better. Hope to see you in 2012!

Grz, Kris.


Monday, 05 December 2011 22:39:00 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |