Skip to main content
Participant
May 23, 2013
Answered

CFContent open file with # in filename

  • May 23, 2013
  • 1 reply
  • 1310 views

I am trying to launch a file when the user clicks on a link. Sometimes the filename has a # sign in the name, like "My File #1.xlsx". When they click it, they get an error saying "The file specified in the contentTag does not exist" and then the shows .../My File not found.

Additionally, though I can't remember for sure at the moment, I think I've had trouble with a few other characters such as  ^, *, ?, ", <, >, |. And consecutive periods (.) like My...Filename.xlsx. However, I can live with that problem but not the # in the filename!

Surely there's something I can do to launch such a file.

Here's what I'm using:

this is the call: <td><a href="./fileopener.cfm?attached_file=true&file_location=#qryGetFileNames.ServerDirectory#\#qryGetFileNames.ServerFile#">#qryGetFileNames.ServerFile#</a></td>

<cfset file_location = "#url.file_location#">

<cfheader name="content-disposition" value="attachment;filename=#file_location#">

<cfcontent deleteFile="no" file=#file_location# reset="yes">

Thank you.

This topic has been closed for replies.
Correct answer WolfShade

Have you tried escaping the # ?

#replace(file_location,"#","##","all")#

OR

In the URL: #URLEncodedFormat(qryGetFileNames.ServerFile)#

^_^

1 reply

WolfShade
WolfShadeCorrect answer
Legend
May 24, 2013

Have you tried escaping the # ?

#replace(file_location,"#","##","all")#

OR

In the URL: #URLEncodedFormat(qryGetFileNames.ServerFile)#

^_^

KevDFischAuthor
Participant
May 28, 2013

In the URL: #URLEncodedFormat(qryGetFileNames.ServerFile)# did the trick!