• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Open a file using URL

Explorer ,
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
TOPICS
Advanced techniques

Views

250

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 20, 2007 Mar 20, 2007

Copy link to clipboard

Copied

LATEST
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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation