对于新的Intranet应用程序,我想让用户add a calendar to their Outlook以便轻松查看。日历将是只读的。我该如何创建它?
答案 0 :(得分:4)
您应该创建一个大多数客户可以订阅的iCal feed。使用控制器中的FileStreamResult
将其发布到客户端。熟悉ICS规范,就像这样开始
BEGIN:VCALENDAR PRODID:-//{Calender of something}//NONSGML v1.0//EN
VERSION:1.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:{Name}
X-ORIGINAL-URL:{The Url obviously}
X-WR-CALDESC:{Calendar of Events For a new intranet application}
以END:VCALENDAR
结尾。这是事件
BEGIN:VEVENT
DTSTART:20101113
DTEND:20101115
DTSTAMP:20101110T154940
CREATED:20101109T201237
LAST-MODIFIED:20101109T201237
UID:{unique id}
SUMMARY:Nanaimo Artwalk 2010 (Free)
DESCRIPTION:{Description}
LOCATION:{Location}
URL:{url}
END:VEVENT
现在我不太了解ICS格式,所以你应该更熟悉它。或者,您可以使用an open-source library。创建Feed时,请将其写为文件结果。
private static FileResult iCalResult(string ics)
{
return new FileStreamResult(WriteCal(ics), "text/calendar");
}
private static Stream WriteCal(string ics)
{
var content = Encoding.ASCII.GetBytes(ics);
var stream = new MemoryStream(content);
return stream;
}