On of my many, many tasks today is to enable the output of a Notes-based view as an iCalendar (.ics) file, so uses can import it to the own calendar application.
To do this is simple. Just print the content-type "text/calendar" from the outputting agent and then print out all the entries in the required format.
I wrote the code to do this in very little time but then spent just as long wondering why on earth the content wasn't being outputted.
Then I realised what I'd done. Remember a couple of years ago I mentioned a way to print data to the content headers of a page? Inadvertently, that is what I had done.
Here's what my code looked like (simplified to prove a point):
Print "content-type: text/calendar" Print "BEGIN:VCALENDAR" Print "BEGIN:VEVENT" Print "DTSTART;VALUE=DATE:20090909" Print "END:VEVENT" Print "BEGIN:VCALENDAR"
When I opened it in the browser all that was in the file downloaded was:
DTSTART;VALUE=DATE:20090909 END:VEVENT BEGIN:VCALENDAR
After a maddening ten minutes or so I realised that all the lines after the content-type header were also being treated as headers. Firstly because they are in the format "XXX: yyyyy" i.e. a word followed by a colon. Secondly because I hadn't put a blank line between the header and the output. My code should (and does now) have looked like this:
Print "content-type: text/calendar" Print "" Print "BEGIN:VCALENDAR" Print "BEGIN:VEVENT" Print "DTSTART;VALUE=DATE:20090909" Print "END:VEVENT" Print "BEGIN:VCALENDAR"
There's a lesson in there somewhere!
To output your Notes-stored dates in the right format you can do this:
Print "CREATED:"+Format(doc.Created, "yyyymmddThhMM00")
Although you might need to modify that if you want it accurate to the second or you're in a different timezone to GMT etc.