如何为Outlook创建"互联网日历订阅"?

who*_*res 5 icalendar outlook asp.net-mvc-4

目前,用户添加了"新的互联网日历",但它是ICS文件的一次性下载.我希望用户单击按钮以将其个人日历添加为Outlook的订阅.我想要自动更新"互联网日历订阅".

与SharePoint一样,名为"连接到Outlook"的按钮将您正在查看的日历添加为自动同步日历.

JP *_*ons 6

在C#创建iCals这个CodeProject上后告诉我,你应该使用DDAY的iCal库.

DDay.iCal是适用于.NET 2.0及更高版本Silverlight的iCal(RFC 5545)类库.它的目标是尽可能符合RFC 5545,同时针对与流行的日历应用程序兼容,如Apple iCal,Outlook 2007等.

一些iCal + MVC + DDay.iCal的示例代码

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);
}
Run Code Online (Sandbox Code Playgroud)