3 Replies Latest reply on Mar 20, 2007 6:35 AM by insuractive

    Open a file using URL

    rockhiker Level 1
      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
        • 1. Re: Open a file using URL
          insuractive Level 3
          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.
          • 2. Re: Open a file using URL
            LL@Work Level 1
            Here is a simple illustration with the extension hard-coded.

            <cfquery name="getEmps" datasource="cfdocexamples">
            SELECT firstname FROM EMPLOYEE
            <cfoutput query="getEmps">
            <a href="#trim(firstname)#.pdf">#Firstname#</a><br>

            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
            • 3. Re: Open a file using URL
              insuractive Level 3
              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.