Skip to content

Instantly share code, notes, and snippets.

@szul
Created February 20, 2018 16:26
Show Gist options
  • Select an option

  • Save szul/7632ac049e413fda558b95eca75e4565 to your computer and use it in GitHub Desktop.

Select an option

Save szul/7632ac049e413fda558b95eca75e4565 to your computer and use it in GitHub Desktop.
Code snippet for ICS attachment creation
public sealed class EventCalendar
{
private string _ics;
public EventCalendar()
{
}
public EventCalendar(string summary, string description, System.DateTime start, System.DateTime end, string location)
{
StringBuilder sb;
try
{
sb = new StringBuilder();
sb.AppendLine("BEGIN:VCALENDAR");
sb.AppendLine("VERSION:2.0");
sb.AppendLine("PRODID:learn.med.virginia.edu");
sb.AppendLine("CALSCALE:GREGORIAN");
sb.AppendLine("METHOD:PUBLISH");
sb.AppendLine("BEGIN:VEVENT");
sb.AppendLine("DTSTART:" + start.ToString("yyyyMMddTHHmm00"));
sb.AppendLine("DTEND:" + end.ToString("yyyyMMddTHHmm00"));
sb.AppendLine("DTSTAMP:" + DateTime.Now.ToUniversalTime().ToString("yyyyMMddTHHmm00"));
sb.AppendLine("UID:" + Guid.NewGuid().ToString());
sb.AppendLine("CREATED:" + DateTime.Now.ToUniversalTime().ToString("yyyyMMddTHHmm00"));
sb.AppendLine("SUMMARY:" + summary + "");
sb.AppendLine("LOCATION:" + location + "");
sb.AppendLine("DESCRIPTION:" + description + "");
sb.AppendLine("LAST-MODIFIED:" + DateTime.Now.ToUniversalTime().ToString("yyyyMMddTHHmm00"));
sb.AppendLine("SEQUENCE:0");
sb.AppendLine("STATUS:CONFIRMED");
sb.AppendLine("TRANSP:OPAQUE");
sb.AppendLine("PRIORITY:3");
sb.AppendLine("END:VEVENT");
sb.AppendLine("END:VCALENDAR");
this._ics = sb.ToString();
}
finally
{
sb = null;
}
}
public MemoryStream EventStream
{
get
{
return (MemoryStream)IO.Codepunk.Tools.Stream.StringToStream(this._ics);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment