One thing I have been try­ing for months to do on the Fac­ul­ty of Man­age­ment web­site is to cre­ate VCS files on the fly. VCS files are what Out­look and oth­er cal­en­dar­ing soft­ware use to pass cal­en­dar items between each oth­er. When I added an event to our data­base with Cold­Fu­sion, I want­ed it to cre­ate a VCS file that the user could then down­load to his/her cal­en­dar.

Ear­li­er this week, I came across Chris Wigginton’s vCal UDF. This Cold­Fu­sion UDF out­puts the nec­es­sary infor­ma­tion to a string. All that is need­ed is to write the string to a file. I used the fol­low­ing code to accom­plish this:

<cffile action="write" file="/root/folder/folder/file.vcs" nameconflict="overwrite" output="#vCalOutput#" mode="777" />

The cffile tag is used for cre­at­ing, mod­i­fy­ing and delet­ing files with Cold­Fu­sion.

The action attribute is pret­ty self-explana­to­ry.

The file attribute con­tains a path to where the file is/will be stored. This is not a URL. It is a direct serv­er path. It should also be not­ed that some servers will require a dri­ve let­ter (such as C:).

The nameconflict attribute is used to tell Cold­Fu­sion what to do if it encoun­ters a file named the same as that ref­er­enced in the file attribute. I used over­write sim­ply because I was using the cffile tag in an edit page. In this regard I was mak­ing changes to the event in the data­base, so I want­ed those changes reflect­ed in the VCS file.

The output attribute is what is sent to the file ref­er­enced in the file attribute.

The mode attribute is the per­mis­sions giv­en to the file. Our serv­er does some pret­ty funky things some­times, so I gave read, write and exe­cute to the own­er, group and world. Any­thing else would prob­a­bly result in a Cold­Fu­sion serv­er error.

One oth­er thing to keep in mind with VCS files is that times are based on GMT. In order for me to cre­ate times for the Moun­tain Time Zone, I had to add 6 hours to the start and end times. For this, I used the fol­low­ing code:

stEvent.endTime = "#DateAdd('H', 6, CreateODBCTime(FORM.TimeEnd))#";

The first para­me­ter of the DateAdd func­tion is which ele­ment of the date/time val­ue you want to change. In this case, ‘H’ cor­re­sponds to the hour. The sec­ond para­me­ter is the num­ber of hours to use. If you live east of the GMT, you would sim­ply use a neg­a­tive val­ue. The third para­me­ter is anoth­er func­tion that con­verts the time-only val­ue I use in my data­base to a date and time val­ue need­ed for the VCS file. If you use a date-time val­ue in your data­base already, you don’t need to use the CreateODBCTime() func­tion.

There you are. A com­plete solu­tion to mak­ing VCS files in Cold­Fu­sion.

Update: For some rea­son, VCS files do not seem to cur­rent­ly work in Fire­fox.

About Kim Siever

I am a copy­writer and copy­ed­i­tor. I blog on writ­ing tips most­ly, but I some­times throw in my thoughts about run­ning a small busi­ness.

Fol­low me on Twit­ter at @hotpepper.

Free monthlywriting &social media tips!

Free monthlywriting &social media tips!

Sign up to receive monthly writing and social media tips.

Thanks for signing up for our monthly writing tips!

Pin It on Pinterest