目前,用户添加了“新的互联网日历”,但它是一次性下载ICS文件。我希望用户单击按钮以将其个人日历添加为Outlook的订阅。我希望自动更新"internet calendar subscription"。
与SharePoint一样,名为“连接到Outlook”的按钮会将您正在查看的日历添加为自动同步日历。
答案 0 :(得分:6)
Creating iCals in C#和this CodeProject post告诉我你应该使用DDay iCal Library。
DDay.iCal是适用于.NET 2.0及更高版本Silverlight的iCal(RFC 5545)类库。它的目标是尽可能符合RFC 5545,同时针对与Apple iCal,Outlook 2007等流行的日历应用程序兼容。
iCal + MVC + DDay.iCal的一些sample code
public ActionResult iCalendar(string DownloadFileName)
{
DDay.iCal.iCalendar iCal = new DDay.iCal.iCalendar();
Event evt = iCal.Create<Event>();
evt.Start = iCalDateTime.Today.AddHours(8);
evt.End = evt.Start.AddHours(18); // This also sets the duration
evt.Description = "The event description";
evt.Location = "Event location";
evt.Summary = "18 hour event summary";
evt = iCal.Create<Event>();
evt.Start = iCalDateTime.Today.AddDays(5);
evt.End = evt.Start.AddDays(1);
evt.IsAllDay = true;
evt.Summary = "All-day event";
ISerializationContext ctx = new SerializationContext();
ISerializerFactory factory = new DDay.iCal.Serialization.iCalendar.SerializerFactory();
IStringSerializer serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer;
string output = serializer.SerializeToString(iCal);
var contentType = "text/calendar";
var bytes = Encoding.UTF8.GetBytes(output);
return File(bytes, contentType, DownloadFileName);
}