Created
January 18, 2019 16:37
-
-
Save ashelopukho/75a04cb49ad1ac91ccd164bd15040069 to your computer and use it in GitHub Desktop.
icsGen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Ical.Net; | |
using Ical.Net.CalendarComponents; | |
using Ical.Net.DataTypes; | |
using Ical.Net.Serialization; | |
using Microsoft.SharePoint; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var now = DateTime.Now.AddDays(5); | |
var later = now.AddHours(1); | |
//Repeat daily for 5 days | |
var rrule = new RecurrencePattern(FrequencyType.Daily, 1) { Count = 5 }; | |
string formatted = @"FMTTYPE=text/html:<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 3.2//E | |
N"">\n<HTML>\n<HEAD>\n<META NAME=""Generator"" CONTENT=""MS Exchange Server ve | |
rsion rmj.rmm.rup.rpr"">\n<TITLE></TITLE>\n</HEAD>\n<BODY>\n | |
<!-- Converted from text/rtf format -->\n\n | |
<UL><LI>000000000000000</LI><LI>000000000000000</LI><LI>000000000000000</LI><LI>000000000000000</LI></UL>\n\n</BODY>\n</HTML>"; | |
List<CalendarEvent> events = new List<CalendarEvent>(); | |
for (int i = 0; i < 7; i++) | |
{ | |
var property = new CalendarProperty("X-ALT-DESC", formatted); | |
var e = new CalendarEvent | |
{ | |
Start = new CalDateTime(now.AddDays(i + 2)), | |
End = new CalDateTime(now.AddDays(i + 2).AddHours(2)), | |
Summary = "RENAT" + Path.GetRandomFileName().Substring(0, 4), | |
}; | |
e.AddProperty(property); | |
events.Add(e); | |
} | |
var calendar = new Calendar(); | |
calendar.AddProperty("X-WR-CALNAME", "Ash Test Calendar"); | |
calendar.AddProperty("X-PUBLISHED-TTL", "PT1H"); | |
calendar.Events.AddRange(events); | |
var serializer = new CalendarSerializer(); | |
var serializedCalendar = serializer.SerializeToString(calendar); | |
serializedCalendar = serializedCalendar.Replace("X-ALT-DESC:FMTTYPE=text/html", "X-ALT-DESC;FMTTYPE=text/html"); | |
File.WriteAllText("myc.ics", serializedCalendar); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment