[英]How to make .ics file as downloadable c#
为了导出.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驱动器或按照我们给定的路径写入文件。 但我需要它可以下载。
我尝试了一些代码,但这不是我需要的确切格式。
提前致谢。
该文档支持使用流。 您可以将日历的内容写到响应中。 确保同时设置了MIME类型。
iCalendarSerializer serializer = new iCalendarSerializer(iCal);
serializer.Serialize(Response.OutputStream, Encoding.ASCII);
http://www.ddaysoftware.com/Pages/Projects/DDay.iCal/Documentation/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.