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

Calendar

Sun Mon Tue Wed Thu Fri Sat
      1
2 3 4 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       

Subscribe

Enter your email address to subscribe to this blog.

Tags

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

Recent Comments

Ajax Form Submission Revisited And Advice Needed
Hammo777 said: To solve your original problem: document.formname.onsubmit(); just call the onsubmit method yourse... [More]

Editing A Query In A SQL Server DTS Package
JD said: Thanks for your post. Never unlike Microsoft to hide stuff in the hardest part time find. [More]

Mashing Spry Effects With CF8 Ajax Goodness
Mark Pitts said: I have had moderate success implementing Spry Accordian. Sadly the part that does is not working wil... [More]

Chinese Birth Calendar Accuracy Test
Toni Lehman said: This calendar was accurate for both my daughters and 4 grandchildren. I tried it for 11 of my other ... [More]

Virtual Memory - Am I The Last To Know?
Larry Miller said: The authors friend was right. Windows virtual memory system was designed by experts and they fully u... [More]

RSS


coldfusionbloggers

FullAsAGoog MXNA

Consumed By Feed-Squirrel.com