provides custom format (doc) - specifying file name and extension

48 views
Skip to first unread message

Mike Henke

unread,
May 7, 2011, 6:49:49 PM5/7/11
to ColdFusion on Wheels
Hi,

I am looking into responding with multiple formats. I was following
the word doc example in http://cfwheels.org/docs/1-1/chapter/responding-with-multiple-formats

Everything seems fine but I was wondering how to specify a file name
and extension. Currently in Chrome if I try
http://wheels.local/index.cfm/articles/index?format=doc

It downloads "index". I would like the file to return as "list.doc".

Thanks,

AJ Mercer

unread,
May 10, 2011, 4:02:57 AM5/10/11
to cfwh...@googlegroups.com
to do this I think you will have to get 
    <cfheader name="Content-Disposition" VALUE='attachment|inline;filename="#ARGUMENTS.[file name variable here]#"'>
added to $content()


--
You received this message because you are subscribed to the Google Groups "ColdFusion on Wheels" group.
To post to this group, send email to cfwh...@googlegroups.com.
To unsubscribe from this group, send email to cfwheels+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cfwheels?hl=en.




--

AJ Mercer
<webonix:net strength="Industrial" /> | <webonix:org community="Open" />
http://twitter.com/webonix

Chris Peters

unread,
May 10, 2011, 8:32:36 AM5/10/11
to cfwh...@googlegroups.com
Or just add that cfheader tag to the top of your view file.

jjallen

unread,
May 10, 2011, 12:06:21 PM5/10/11
to cfwh...@googlegroups.com
or - couldn't you just create an empty views/articles/list.doc.cfm then setup a route to link that with the intended controller/action, then linkTo that route, instead of to the index?

From testing with a similar setup (albeit with csv vs doc), the attachment/download seems to take the file name from the name of the view.

Here's an example of what I did in my case to get that to work:
<code>
<!--- routes --->
<cfset addRoute(name="contactExport", pattern="contact/export.[format]",
                controller="contact", action="export")>

<!--- Controller Contact.cfc --->
// init
<cfset provides("html,csv")>

// export function
<snip>
RenderWith(allContacts)

Then on the "main" view:
<cfoutput>
#linkTo(route="contactExport", format="csv")#
</cfoutput>

Then I just created an empty file at views/contacts/export.csv.cfm

...afaik, that should work regardless of the format so doc should work the same no?

It seems like more to setup...but once you have it working once, it becomes easier to manage/replicate as needed.  Also then, if you need to do anything to format or filter the data, you can do so to a degree in the view file (i.e. export.csv.cfm above).  While probably not as useful/necessary with doc, seems handy when working with csv/excel and maybe pdf.





Mike Henke

unread,
May 10, 2011, 5:14:30 PM5/10/11
to ColdFusion on Wheels
Thanks guys!!! I'll review all the suggestion and fix my training
example.

AJ Mercer

unread,
May 10, 2011, 8:35:26 PM5/10/11
to cfwh...@googlegroups.com
this works nicely - thanks for the tip Chris

in the view

...
<cfset jqGrid = serializeJSON(jqGrid) />
<cfheader name="Content-Disposition" VALUE='filename="ajm.json"'>
<cfoutput>#jqGrid#</cfoutput>

Jeff Bourassa

unread,
Jun 5, 2012, 10:15:11 PM6/5/12
to cfwh...@googlegroups.com
When I add this I am simply getting my CSV file displaying in the Browser window, it is not being downloaded as a file - ideally I would like it downloaded as a file, with a name that I specify.

I have added to my index.csv.cfm template for a CSV export:

<cfheader name="Content-Disposition" VALUE='filename="filename.csv"'>

The data is in the format I want, csv, as I formatted in my csv template file - however it is being displayed in the browser, possibly a content type problem I am thinking?  Any suggestions?



Jeff

added to $content()

To unsubscribe from this group, send email to cfwheels+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/cfwheels?hl=en.

--
You received this message because you are subscribed to the Google Groups "ColdFusion on Wheels" group.
To post to this group, send email to cfwh...@googlegroups.com.
To unsubscribe from this group, send email to cfwheels+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/cfwheels?hl=en.

--
You received this message because you are subscribed to the Google Groups "ColdFusion on Wheels" group.
To post to this group, send email to cfwh...@googlegroups.com.
To unsubscribe from this group, send email to cfwheels+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/cfwheels?hl=en.

Jeff Bourassa

unread,
Jun 5, 2012, 10:20:54 PM6/5/12
to cfwh...@googlegroups.com
Use this....

<cfheader name="Content-Disposition" VALUE='attachment|inline;filename="filename.csv"'>


Works....
Reply all
Reply to author
Forward
0 new messages