首页 文章

在Google Calendar API中导入/导出.ical

提问于
浏览
1

我在Google日历的Web界面中看到,可以选择下载我日历的.ical版本 . 我希望在我开发的应用程序中执行此操作 . 我正在查看互联网和文档中是否有类似的东西,但我找不到任何东西...... API是否提供此功能?如果是,我该如何开始这样做?

1 回答

  • 4

    为了确保我理解您的问题,您希望在Web应用程序上提供“下载为.ical”按钮,并使用您应用程序中的特定日历事件数据动态填充?

    将一个ical文件(或更准确地说,一个.ics文件)想象成一个字符串,但使用不同的Mime类型 . 以下描述了iCalendar格式的基础知识:

    http://en.wikipedia.org/wiki/ICalendar

    在ASP.NET中,我需要提供完整的网页 . 在处理程序中,用这样的东西替换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();
    }
    

相关问题