1

对于 .ics 文件的导出,我编写了以下代码。折叠 | 复制代码

iCalendar iCal = new iCalendar();
            foreach (DataRow row in dt.Rows)
            {
                // Create the event, and add it to the iCalendar
                Event evt = iCal.Create<event>();

            // Set information about the event
            evt.Start = (DDay.iCal.iCalDateTime)Convert.ToDateTime(row["StartDate"]);
            evt.End = (DDay.iCal.iCalDateTime)Convert.ToDateTime(row["EndDate"]);// This also sets the duration
            evt.Description = (string)row["Description"];
        }


     // Serialize (save) the iCalendar
 iCalendarSerializer serializer = new iCalendarSerializer();
        serializer.Serialize(iCal, @"C:\iCalendar.ics");

它对我来说工作正常,但它会将文件写入 C 驱动器或按照我们给出的路径。但我需要它是可下载的。

我尝试了一些代码,但这不是我需要的确切格式。

提前致谢。

4

1 回答 1

2

文档支持使用流。您可以将日历的内容写入响应。确保您也设置了 mime 类型。

iCalendarSerializer serializer = new iCalendarSerializer(iCal);
serializer.Serialize(Response.OutputStream, Encoding.ASCII);

http://www.ddaysoftware.com/Pages/Projects/DDay.iCal/Documentation/

于 2014-08-04T16:15:31.953 回答