How do I create an Outlook "internet calendar subscription"?
For a new intranet application, I would like to let the user add a calendar to their Outlook so it can be easily looked at. The calenda开发者_如何学Pythonr would be read-only. How do I go about creating this?
You should create an iCal feed which most clients can subscribe to. Use a FileStreamResult
in your controller to post it down to clients. Get familiar with the ICS specification, it starts like this
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}
and ends with END:VCALENDAR
. And here are events
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
Now I don't know the ICS format really well so you should get more acquainted with it. Alternatively you can use an open-source library. When you create your feed write it as a file result.
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;
}
精彩评论