Highlighted

Link a file using ColdFusion Variable

Engaged ,
Jul 07, 2016

Copy link to clipboard

Copied

I have following code to generate a csv file using my stored procedure return.

After file created, I create a link to let user access.

The link does not add my file name variable.

Are there any better way to add my variable to the link that user can access the file just created or just created the file on the local machine that user can access

locally?

Your information and help is great appreciated,

Regards,

  <Cfset thisPath = ExpandPath("*.*")>

     <cfset f_dir = GetDirectoryFromPath(thisPath)>

   <cfset f_name = "#dateformat(now(), 'mmddyy')##timeformat(now(), 'hhmm')#.csv">

   <cffile action="WRITE" file="#f_dir##f_name#"

   output="MtField1, MyField2" addnewline="Yes">

   <cfloop query="#myQuery#">

   <cffile action="APPEND" file="#f_dir##f_name#"

   output="#Field1#, #Field2#  addnewline="Yes">

   </cfloop>

   <br>

   <a href="MyServer\Report\" + #f_name#>Here is the file</a>

Adobe Community Professional
Correct answer by BKBK | Adobe Community Professional

Thanks, EddieLotter. I missed that one.

Let me compensate with this remark:

<cfset theLink = "MyServer/Report/" & f_name>

<cfoutput><a href="#theLink#">Here is the file</a></cfoutput>

TOPICS
Getting started

Views

1.1K

Likes

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

Link a file using ColdFusion Variable

Engaged ,
Jul 07, 2016

Copy link to clipboard

Copied

I have following code to generate a csv file using my stored procedure return.

After file created, I create a link to let user access.

The link does not add my file name variable.

Are there any better way to add my variable to the link that user can access the file just created or just created the file on the local machine that user can access

locally?

Your information and help is great appreciated,

Regards,

  <Cfset thisPath = ExpandPath("*.*")>

     <cfset f_dir = GetDirectoryFromPath(thisPath)>

   <cfset f_name = "#dateformat(now(), 'mmddyy')##timeformat(now(), 'hhmm')#.csv">

   <cffile action="WRITE" file="#f_dir##f_name#"

   output="MtField1, MyField2" addnewline="Yes">

   <cfloop query="#myQuery#">

   <cffile action="APPEND" file="#f_dir##f_name#"

   output="#Field1#, #Field2#  addnewline="Yes">

   </cfloop>

   <br>

   <a href="MyServer\Report\" + #f_name#>Here is the file</a>

Adobe Community Professional
Correct answer by BKBK | Adobe Community Professional

Thanks, EddieLotter. I missed that one.

Let me compensate with this remark:

<cfset theLink = "MyServer/Report/" & f_name>

<cfoutput><a href="#theLink#">Here is the file</a></cfoutput>

TOPICS
Getting started

Views

1.1K

Likes

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
Jul 07, 2016 0
Adobe Community Professional ,
Jul 07, 2016

Copy link to clipboard

Copied

Supply missing quotes: <cffile action="APPEND" file="#f_dir##f_name#" output="#Field1#, #Field2#"  addnewline="Yes">

Use cfoutput: <cfoutput><a href="MyServer\Report\" + #f_name#>Here is the file</a></cfoutput>

Likes

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
Reply
Loading...
Jul 07, 2016 0
Advocate ,
Jul 07, 2016

Copy link to clipboard

Copied

This link is malformed:

<a href="MyServer\Report\" + #f_name#>Here is the file</a>

It should be:

<a href="MyServer/Report/#f_name#">Here is the file</a>

You can verify this in your Web browser by looking at the source HTML generated by your Web server.

Cheers

Eddie

Likes

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
Reply
Loading...
Jul 07, 2016 0
Adobe Community Professional ,
Jul 07, 2016

Copy link to clipboard

Copied

Thanks, EddieLotter. I missed that one.

Let me compensate with this remark:

<cfset theLink = "MyServer/Report/" & f_name>

<cfoutput><a href="#theLink#">Here is the file</a></cfoutput>

Likes

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
Reply
Loading...
Jul 07, 2016 0
iccsi LATEST
Engaged ,
Jul 08, 2016

Copy link to clipboard

Copied

Thanks for help and information,

BKBK's code works for my browser, but my browser opens it as a text file, it does not use Excel to open it as a CSV file.

I would like to know is it possible to have user select or save the file on user's machine in MyDocument using ColdFusion or I need JavaScript or jQuery to do the task.

Thanks again for your information and help,

Regards,

Sourises

Likes

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
Reply
Loading...
Jul 08, 2016 0