0
Open a file using URL
Explorer
,
/t5/coldfusion-discussions/open-a-file-using-url/td-p/598171
Mar 19, 2007
Mar 19, 2007
Copy link to clipboard
Copied
In my data base I have a field called AgendaDocument. The
values of this field are just the document name (like JulyAgenda)
with no file extension. Most of these are pdf. I want the user to
click a dynamically created link to open the document. Please help
- see code
thanks
thanks
TOPICS
Advanced techniques
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Advocate
,
/t5/coldfusion-discussions/open-a-file-using-url/m-p/598172#M55548
Mar 19, 2007
Mar 19, 2007
Copy link to clipboard
Copied
Are the documents stored on the server, or stored as binary
data in the database? what seems to be the problem? The code looks
ok. I'm assuming you are storing the full path to the document in
the variable URL, in which case clicking on the link should bring
up your document assuming that the file exists on the
server.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Engaged
,
/t5/coldfusion-discussions/open-a-file-using-url/m-p/598173#M55549
Mar 19, 2007
Mar 19, 2007
Copy link to clipboard
Copied
Here is a simple illustration with the extension hard-coded.
<cfquery name="getEmps" datasource="cfdocexamples">
SELECT firstname FROM EMPLOYEE
</cfquery>
<cfoutput query="getEmps">
<a href="#trim(firstname)#.pdf">#Firstname#</a><br>
</cfoutput>
You say " Most of these are pdf."
You will need to leverage ColdFusion's file and string manipulation functions to identify the document extenstion and pass them to the url accordingly
See http://livedocs.adobe.com/coldfusion/7/htmldocs/00000353.htm for help with ColdFusion functions
<cfquery name="getEmps" datasource="cfdocexamples">
SELECT firstname FROM EMPLOYEE
</cfquery>
<cfoutput query="getEmps">
<a href="#trim(firstname)#.pdf">#Firstname#</a><br>
</cfoutput>
You say " Most of these are pdf."
You will need to leverage ColdFusion's file and string manipulation functions to identify the document extenstion and pass them to the url accordingly
See http://livedocs.adobe.com/coldfusion/7/htmldocs/00000353.htm for help with ColdFusion functions
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Advocate
,
LATEST
/t5/coldfusion-discussions/open-a-file-using-url/m-p/598174#M55550
Mar 20, 2007
Mar 20, 2007
Copy link to clipboard
Copied
From Rockhiker's first post, it looks like the filename is
stored in the database without a file extension. Just to clarify,
do you have the full filename (with file extension) stored in your
database? If not, there are solutions, but I would definitely
recommend adding a field for file type to your application.
If you don't have the file extension of the file, but know it is one of only a handful of file types, you can use the fileExists() method to determine the correct filetype:
<cfif FileExists("C:\Some\Directory\#myFile#.pdf")>
<cfset sFullFileName = "#myFile#.pdf">
<cfelseif FileExists("C:\Some\Directory\#myFile#.doc")>
<cfset sFullFileName = "#myFile#.doc">
...
Otherwise, you could leverage <cfdirectory> to get a list of all your files in a query format and then compare your filename against the values in the directory.
If you don't have the file extension of the file, but know it is one of only a handful of file types, you can use the fileExists() method to determine the correct filetype:
<cfif FileExists("C:\Some\Directory\#myFile#.pdf")>
<cfset sFullFileName = "#myFile#.pdf">
<cfelseif FileExists("C:\Some\Directory\#myFile#.doc")>
<cfset sFullFileName = "#myFile#.doc">
...
Otherwise, you could leverage <cfdirectory> to get a list of all your files in a query format and then compare your filename against the values in the directory.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

