10

I have built a basic calendar event using DDay.iCal, when I click "Add to calendar" link I produce an event and then sends this to the client.

Basically, my application works like this.

  1. A User logs in.
  2. Selects a specific date.
  3. Books a specific timeslot
  4. Clicks the "Add to calendar" link

Sending the event is done by using Response.Write() which sends the following to the client:

Response.ContentType = "text/calendar";
Response.AddHeader("Content-disposition", "attachment; filename=appointment.ics");
Response.Write(iCalString);

The above works fins but it requires me to first book the event then manually and then click the "Add to calendar" link.

I want to merge the steps 3 and 4. But when trying to do so the event booking gets saved to the database but the screen does not get refreshed.

Is there a "simple" way to get around this?

John Saunders
  • 160,644
  • 26
  • 247
  • 397

2 Answers2

1

You need to set up a simple HttpHandler to post the reply and then do a Response.Redirect() into it.

I have done similar work before with integrating the vcard format into an our people section of a website. These articles should tell you everything you need to set up the HttpHandler - just replace the vcard code with your ical code.

When you redirect into the ical handler it will just instantly pop up the download box, you wont be taken to an empty page, the user is left on the same page.

rtpHarry
  • 13,019
  • 4
  • 43
  • 64
1

Make sure that you clear your response (Response.Clear) prior to sending the iCal response information. Finally, end your response (Response.End) before any other content can be emitted. From the end use standpoint this will produce the same result of using an HttpHandler without the hassle.

Christian Specht
  • 35,843
  • 15
  • 128
  • 182
Graham
  • 56
  • 2