One thing I have been trying for months to do on the Faculty of Management website is to create VCS files on the fly. VCS files are what Outlook and other calendaring software use to pass calendar items between each other. When I added an event to our database with ColdFusion, I wanted it to create a VCS file that the user could then download to his/her calendar.
Earlier this week, I came across Chris Wiggintonâ€™s vCal UDF. This ColdFusion UDF outputs the necessary information to a string. All that is needed is to write the string to a file. I used the following code to accomplish this:
<cffile action="write" file="/root/folder/folder/file.vcs" nameconflict="overwrite" output="#vCalOutput#" mode="777" />
cffile tag is used for creating, modifying and deleting files with ColdFusion.
action attribute is pretty self-explanatory.
file attribute contains a path to where the file is/will be stored. This is not a URL. It is a direct server path. It should also be noted that some servers will require a drive letter (such as C:).
nameconflict attribute is used to tell ColdFusion what to do if it encounters a file named the same as that referenced in the
file attribute. I used overwrite simply because I was using the
cffile tag in an edit page. In this regard I was making changes to the event in the database, so I wanted those changes reflected in the VCS file.
output attribute is what is sent to the file referenced in the
mode attribute is the permissions given to the file. Our server does some pretty funky things sometimes, so I gave read, write and execute to the owner, group and world. Anything else would probably result in a ColdFusion server error.
One other thing to keep in mind with VCS files is that times are based on GMT. In order for me to create times for the Mountain Time Zone, I had to add 6 hours to the start and end times. For this, I used the following code:
stEvent.endTime = "#DateAdd('H', 6, CreateODBCTime(FORM.TimeEnd))#";
The first parameter of the
DateAdd function is which element of the date/time value you want to change. In this case, ‘H’ corresponds to the hour. The second parameter is the number of hours to use. If you live east of the GMT, you would simply use a negative value. The third parameter is another function that converts the time-only value I use in my database to a date and time value needed for the VCS file. If you use a date-time value in your database already, you don’t need to use the
There you are. A complete solution to making VCS files in ColdFusion.
Update: For some reason, VCS files do not seem to currently work in Firefox.
Support this story
- 112 people sent me a one-time donation.
- 164 people send me a donation every month.
- 209 people receive my monthly newsletter.