1

For Exporting of .ics file i wrote the following code. 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. but i need it to be downloadable.

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

Thanks in advance.

Ondrej Svejdar
  • 21,349
  • 5
  • 54
  • 89
user3047483
  • 15
  • 1
  • 5

1 Answers1

2

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.

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

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

Ken Brittain
  • 2,255
  • 17
  • 21
  • Sorry but, i dont get it. I tryed and i got this http://prntscr.com/49hg9k Sorry i'am beginner. Thanks for the reply. – user3047483 Aug 04 '14 at 16:34
  • Which version of DDay.iCal.dll are you using? There is an overload that accepts `Stream` - http://www.ddaysoftware.com/pages/projects/dday.ical/documentation/html/4284d3a3-10b5-16a2-2c13-de241494838c.htm – Abhinav Aug 04 '14 at 17:31
  • @Abhinav now im using the correct version! Thanks! My problem now is i cant download it. When im click the button who contains the method, only put the code of my ics in the top of the page. – user3047483 Aug 04 '14 at 19:48
  • Now its work!! I missed this Response.AddHeader("Content-Disposition", "attachment; filename=" + DateTime.Now + ".ics"); Response.Flush(); Response.Close(); Response.End(); – user3047483 Aug 04 '14 at 20:45