Categories
Uncategorized

Creating VCS Files in ColdFusion

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.

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" />
The cffile tag is used for creating, modifying and deleting files with ColdFusion.
The action attribute is pretty self-explanatory.
The 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:).
The 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.
The output attribute is what is sent to the file referenced in the file attribute.
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 CreateODBCTime() function.
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. Donate once
  • 164 people send me a donation every month. Donate monthly
  • 209 people receive my monthly newsletter. Sign up

By Kim Siever

I live in Lethbridge with my spouse and 5 of our 6 children. I’m a writer, focusing on political news, social issues, and the occasional poem. My politics are radically left. I recently finished writing a book debunking several capitalism myths. My newest book writing project is on the labour history of Lethbridge.

I’m also dichotomally Mormon. And I’m a functional vegetarian: I have a blog post about that somewhere around here. My pronouns are he/him, and I’m queer.

One reply on “Creating VCS Files in ColdFusion”

Comment on this story

This site uses Akismet to reduce spam. Learn how your comment data is processed.