Adding Attachments To A CFPresentation

The other day my buddy Ray suggested that I allow attachments to presentations on SlideSix. I thought it was a great idea, but when I checked the docs for <cfpresentation> I was surprised to find that the tag did not support attachments out of the box. However, after a bit of hackery I found a way to do it.

When you create a preso with cfpresentation and write it to disk there is a subdirectory created called 'data'. Within the 'data' directory are a handful of XML config files and whatnot, and a few of these files are the key to adding attachments. The first mod needed is to enable the presentation UI button that indicates that there are attachments. Doing this is as simple as modding the vconfig.xml file and changing this:

<uishow name="attachments" value="false"/>

To:

<uishow name="attachments" value="true"/>

Once you've done this and have reloaded your generated presentation (clear your cache if necessary) you will see a paper clip attachment indicating that there are attachments (although we haven't added any yet).

To add the actual attachments you'd need to modify the 'viewer.xml' file and add an <attachments> block (wow go figure, who woulda thunk of that name?). The attachments block goes inside the <presentation> node - I put mine below the <slides> block (not sure if the position matters or not). The attachments block takes 1-n <attachment> children - each of which take a url and name attribute. The url points to the attached file and the name is the text label that is used to link to the attachment. Here's how my attachments block looks:

<attachments>
   <attachment name="test with attachment4" url="http://mysite.com/index.cfm?event=attachment.download&slideShowID=1"/>
</attachments>

If you look at the image above you'll see what the attachment looks like after saving the changes to viewer.xml. I decided it was best to point to a CFM page that serves the attachment up with <cfcontent>. And that's it, attachments added to your cfpreso.

It's probably worth noting that you'd probably be better off using CF to make these changes since you'd probably not want to manually change these settings every time you write your cfpresentation to disk. Since CF can easily modify XML there's no reason not to automate the changes with a bit of code. Here is what my code looks like to do that:

<!--- read in the xml files --->
<cffile action="read" file="#viewer#" variable="viewerXML" />
<cffile action="read" file="#vconfig#" variable="vconfigXML" />

<!--- parse the xml --->
<cfset viewerXML = xmlParse(viewerXML) />
<cfset vconfigXML = xmlParse(vconfigXML) />

<!--- get the node that contains the 'attachment' value --->
<cfset vconfigAtt = xmlSearch(vconfigXML,"//configuration/layout/uishow[@name='attachments']") /> <!--- set attachments to 'true' so the UI displays the paper clip icon --->
<cfset vconfigAtt[1].XMLAttributes.value = "true" />

<!--- add an 'attachments' block to the viewer xml --->
<cfset viewerXML.presentation.XMLChildren[arrayLen(viewerXML.presentation.XMLChildren)+1] = xmlElemNew(viewerXML,"attachments") />
<!--- add an 'attachment' block to the 'attachments' block --->
<cfset viewerXML.presentation.attachments.XMLChildren[arrayLen(viewerXML.presentation.attachments.XMLChildren)+1] = xmlElemNew(viewerXML, "attachment") />

<!--- set the url where the attachment is served from --->
<cfset viewerXML.presentation.attachments.attachment.XMLAttributes["url"] = "http://myurl" />
<cfset viewerXML.presentation.attachments.attachment.XMLAttributes["name"] = "text to be displayed" />

<!--- write the xml back to the files --->
<cffile action="write" file="#viewer#" output="#toString(viewerXML)#" />
<cffile action="write" file="#vconfig#" output="#toString(vconfigXML)#" />



Comments
Excellent detective work.. Todd! We knew people would find a way to do this and that is why we didnt do it ;-)
# Posted By Rupesh | 5/31/08 1:29 AM
Thanks Rupesh. I should have also mentioned that using an <external> block under attachments lets you point to an external url and that <local> does the same thing as <attachment>. Wonder what other hidden goodies are in CF8??
# Posted By todd sharp | 6/2/08 9:39 AM
Is this still possible using the cf 8 Developer edition, or does it work in standard and enterprise versions only. I can't seem to find the data directory you are mentioning.
# Posted By JoeRav | 11/26/08 3:21 PM
Yes it should work for you. You don't see a data directory as part of the files that are written to disk for your cfpresentation?
# Posted By todd sharp | 11/26/08 3:31 PM
No, my file is right under the wwwroot directory.Ii don't see any children data folders. Could it be placing this folder somewhere else?
# Posted By JoeRav | 11/26/08 3:36 PM

Calendar

Sun Mon Tue Wed Thu Fri Sat
   1234
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

Subscribe

Enter your email address to subscribe to this blog.

Tags

actionscript ajax blogging cfsnippets coldfusion flash forms flex funny stuff javascript misc model-glue off topic personal project learn slidesix sql

Recent Comments

Adding Auto Generated Code Downloads to BlogCFC
ada5fsa said: http://www.ibiblio.org/st... http://www.ncaonline.org/...... [More]

Chinese Birth Calendar Accuracy Test
mama to be said: ok so i will be 2 months shy of 18 when i have my baby. this calendar does not technically work for ... [More]

Fixing 'User Profile Service Failed The Logon' on Vista
Mike said: That fix worked although all i did was remove .bak and reset state to 0. User was able to log in to... [More]

Chinese Birth Calendar Accuracy Test
Melissa said: Wrong for my daughter, which it predicted to be a boy... we'll see for #2. Predicts a girl (maybe, f... [More]

Adding Auto Generated Code Downloads to BlogCFC
fweerw said: http://www.ibiblio.org/st... http://www.cambodia.ait.a...... [More]

RSS


adobe community experts

coldfusionbloggers

FullAsAGoog MXNA

Consumed By Feed-Squirrel.com