Dim*_*Zli 1 .net c# icalendar google-calendar-api
我在Google日历的Web UI中看到可以选择下载日历的.ical版本。我想在我开发的应用程序中做到这一点。我正在Internet和文档中查找是否存在类似的内容,但找不到任何内容... API是否提供此功能?如果是,我该如何开始?
为确保我理解您的问题,您希望在Web应用程序上提供一个“以.ical下载”按钮,该按钮动态填充了来自应用程序的特定日历事件数据吗?
可以将ical文件(或更准确地说是.ics文件)视为一个字符串,但是具有不同的Mime类型。下面介绍iCalendar格式的基本知识:
http://en.wikipedia.org/wiki/ICalendar
在ASP.NET中,我建议创建一个处理程序(.ashx而不是.aspx),因为如果不需要提供完整的网页,它会更加高效。在处理程序中,将ProcessRequest方法替换为类似的内容(贷方到http://webdevel.blogspot.com/2006/02/how-to-generate-icalendar-file-aspnetc.html)
private string DateFormat
{
get { return "yyyyMMddTHHmmssZ"; } // 20060215T092000Z
}
public void ProcessRequest(HttpContext context)
{
DateTime startDate = DateTime.Now.AddDays(5);
DateTime endDate = startDate.AddMinutes(35);
string organizer = "foo@bar.com";
string location = "My House";
string summary = "My Event";
string description = "Please come to\\nMy House";
context.Response.ContentType="text/calendar";
context.Response.AddHeader("Content-disposition", "attachment; filename=appointment.ics");
context.Response.Write("BEGIN:VCALENDAR");
context.Response.Write("\nVERSION:2.0");
context.Response.Write("\nMETHOD:PUBLISH");
context.Response.Write("\nBEGIN:VEVENT");
context.Response.Write("\nORGANIZER:MAILTO:" + organizer);
context.Response.Write("\nDTSTART:" + startDate.ToUniversalTime().ToString(DateFormat));
context.Response.Write("\nDTEND:" + endDate.ToUniversalTime().ToString(DateFormat));
context.Response.Write("\nLOCATION:" + location);
context.Response.Write("\nUID:" + DateTime.Now.ToUniversalTime().ToString(DateFormat) + "@mysite.com");
context.Response.Write("\nDTSTAMP:" + DateTime.Now.ToUniversalTime().ToString(DateFormat));
context.Response.Write("\nSUMMARY:" + summary);
context.Response.Write("\nDESCRIPTION:" + description);
context.Response.Write("\nPRIORITY:5");
context.Response.Write("\nCLASS:PUBLIC");
context.Response.Write("\nEND:VEVENT");
context.Response.Write("\nEND:VCALENDAR");
context.Response.End();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6295 次 |
| 最近记录: |