using CelticCalendarCalculator.Model; using CelticCalendarCalculator.Model.Constants; using System.Text; namespace CelticCalendarCalculator.Control { internal class Ics { public static void createIcs() { //some variables for demo purposes DateTime DateStart = DateTime.Now; DateTime DateEnd = DateStart.AddMinutes(105); string Summary = "Small summary text"; string Location = "Event location"; string Description = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit."; string FileName = "CalendarItem"; //create a new stringbuilder instance StringBuilder sb = new StringBuilder(); //start the calendar item sb.AppendLine("BEGIN:VCALENDAR"); sb.AppendLine("VERSION:2.0"); sb.AppendLine("PRODID:stackoverflow.com"); sb.AppendLine("CALSCALE:GREGORIAN"); sb.AppendLine("METHOD:PUBLISH"); //create a time zone if needed, TZID to be used in the event itself sb.AppendLine("BEGIN:VTIMEZONE"); sb.AppendLine("TZID:Europe/Amsterdam"); sb.AppendLine("BEGIN:STANDARD"); // oh no.... CreateTimezoneIndicator(); sb.AppendLine(IcaConstants.offset + CreateTimezoneIndicator()); sb.AppendLine(IcaConstants.offsetfrom + CreateTimezoneIndicator()); sb.AppendLine("END:STANDARD"); sb.AppendLine("END:VTIMEZONE"); //add the event sb.AppendLine("BEGIN:VEVENT"); //with time zone specified sb.AppendLine("DTSTART;TZID=Europe/Amsterdam:" + DateStart.ToString("yyyyMMddTHHmm00")); sb.AppendLine("DTEND;TZID=Europe/Amsterdam:" + DateEnd.ToString("yyyyMMddTHHmm00")); //or without sb.AppendLine("DTSTART:" + DateStart.ToString("yyyyMMddTHHmm00")); sb.AppendLine("DTEND:" + DateEnd.ToString("yyyyMMddTHHmm00")); sb.AppendLine("SUMMARY:" + Summary + ""); sb.AppendLine("LOCATION:" + Location + ""); sb.AppendLine("DESCRIPTION:" + Description + ""); sb.AppendLine("PRIORITY:3"); sb.AppendLine("END:VEVENT"); //end calendar item sb.AppendLine("END:VCALENDAR"); //create a string from the stringbuilder string CalendarItem = sb.ToString(); } private static string CreateTimezoneIndicator() { String result = ":"; string operatorstr = Config.timeOffset >= 0 ? "+" : "-"; result += operatorstr; if (Config.timeOffset <= 9) { result += "0"; } result += Config.timeOffset.ToString(); result += IcaConstants.postfix; return result; } } }