如何使.ics文件可下载 [英] how to make .ics file as downloadable

查看:130
本文介绍了如何使.ics文件可下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..

为了导出.ics文件,我编写了以下代码.

Hi..

For Exporting of .ics file i wrote the following 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");


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

我尝试了一些代码,但它不是我所需的确切格式.

在此先感谢...


It is working fine for me but it writes file into C drive or as per the path we have given. but i need it to be downloadable.

i tried some code but it is not the exact format i needed.

Thanks in advance...

推荐答案

有几种方法可以做到这一点.一种方法是覆盖Response并将文件本质上读入Response对象.请参见此处 [
There are several ways to do it. One way is to overwrite the Response and essentially read the file into the Response object. See here[^] for one of many examples.

The other way is to save the file into one of the folders in your IIS site instead of the C: drive and then Response.Redirect(pathOfFile) and the user will be prompted to save or open the file.

The first option is likely better so that you do not clutter your hard drive with files.


这篇关于如何使.ics文件可下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆