Date Time format for an ICS File using C#

The most important part of this task is getting the format for the date and time correct. There is a specific format needed for an ICS file, if the format is not correct then current date time is the default that is used.

Assuming your date is in a string format,  you would need to change it the required format using the below code


Kindly note I have added 090000 as the hour/minute/second as in my case the meeting would be default start at 9 AM.

string filePath = string.Empty;

            string path = HttpContext.Current.Server.MapPath(@”\iCal\”);

            filePath = path + subject + “.ics”;

            StreamWriter writer = new StreamWriter(filePath);



            writer.WriteLine(“PRODID:-//hacksw/handcal//NONSGML v1.0//EN”);


            writer.WriteLine(“DTSTART:” + startDate);

            writer.WriteLine(“DTEND:” + endDate );

            writer.WriteLine(“SUMMARY:” + subject);

            writer.WriteLine(“LOCATION:” + location);




            return filePath;

                string fileName = subject + “.ics”;

                Response.BufferOutput = false;

            Response.AddHeader(“content-disposition”, “attachment; filename=” + fileName);

            Response.ContentType = “text/calendar”;

            Response.TransmitFile(Server.MapPath(“ICal/” + fileName));



, ,
Previous Post
Building Client Agency Relationships using Adaptive Survey Calling
Next Post
How to Make the Most of the User Interviews in a Sprint

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed