简体   繁体   English

如何将.ics文件制作为可下载的C#

[英]How to make .ics file as downloadable c#

For Exporting of .ics file i wrote the following code. 为了导出.ics文件,我编写了以下代码。 Collapse | 收合| Copy Code 复制代码

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");

It is working fine for me but it writes file into C drive or as per the path we have given. 对我来说,它工作正常,但它会将文件写入C驱动器或按照我们给定的路径写入文件。 but i need it to be downloadable. 但我需要它可以下载。

i tried some code but it is not the exact format i needed. 我尝试了一些代码,但这不是我需要的确切格式。

Thanks in advance. 提前致谢。

The documentation supports using a stream. 该文档支持使用流。 You could write the contents of the calendar to the response. 您可以将日历的内容写到响应中。 Make sure you set the mime type as well. 确保同时设置了MIME类型。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM