Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSV files , how to always allow file downloads

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

I'm having a nightmare getting IE to download simple CSV files.

The CSV is genarated via a form submission and i've tried two methods as follows...

1. window.open..

This keeps bleeping without any info bar or message, I added the domain to popup blocker, no good, I added domain to trusted sites, still no good, I then had to edit custom level for trusted sites and enable 'prompting' for file downloads.

Finanly this works, the problem is this is in no way user friendly, average Joe doesn't know how to edit these settings, nor should average Joe have to, especially considering the potential for opening your PC up to serious securtiy risk by mistake and changing wrong settings.

2. document.location.href

This method doesn't require any browser settings to be altered, however, every time the CSV file is requested, the info bar pops up saying it has blocked the file download and you have to right click and accept the download, only the file doesn't download the browser refreshes itself, the webpage is reset and you have to re-request the file, only then will it actually download.

I cannot find anyway of telling IE to allow these downloads from this domain, doing all the browser setting as per option 1 makes no difference and the download info bar pop-up continues to show.

Is there any way round this nightmare? I don't have any problems with either method in firefox!

In my server side code i've tried printing the content to the browser as both dispositions (inline / attachment) it doesn't make any difference.

can anyone help?

Thanks 1DMF.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> PERL v1.5 beta (FusionCharts)
 
have you tried serving the file with a MIME type of "text/csv"?

Failing that, try good old "text/plain".

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
it is server with text/csv

here is the full header details in the perl code..
Code:
    print "Content-type: text/csv\n";
    print "Content-disposition: inline; filename=\"myfilename.csv\"\n\n";

I've even tried...
Code:
print "Content-type: text/x-comma-separated-values\n";
    print "Content-disposition: inline; filename=\"myfilename.csv\"\n\n";
as well as text/plain

nothing will stop the file download info bar message and the page reloading after selecting to download the file!

it's extrememly annoying and i'm getting the feeling there is no way wound it in IE.

I really hate to say this, but I might have to start using firefox!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> PERL v1.5 beta (FusionCharts)
 
hmm, well the second one sends you to MSKB's relating only to I.E. 1 - 5.5 and file type association, which isn't the problem.

the first looks interesting though having done a quick search I can't find the perl equivilent to
Code:
session_cache_limiter("public");

It also seems odd that they are recommending sending an application/octet-stream mime type for a plain text ASCII CSV file.

I've tried the octet-steam and it hasn't made any difference.

But the thread does say the session-cache is the key, so I guess I need to find the perl equivilent...

At least i'm not the only one who's been pulling their hair out over this!




"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> PERL v1.5 beta (FusionCharts)
 
well I went and looked up the PHP command and it seems it sends the HTTP headers
Code:
Expires: (sometime in the future, according session.cache_expires)
Cache-Control: public, max-age=(sometime in the future, according to session.cache_expire
Last-Modified: (the timestamp of when the session was last saved)
, well I added
Code:
Cache-Control:public
as well as used octet-stream and i'm still getting the 'windows has stop the file from downloading' security info bar message.

I use the same code for a direct hyperlink and mp3 files and don't have these problems.

Basically a webform fires a perl script with a query string via AJAX, the result is returned to the script which is authentication that the CSV file can be obtained..

the JS then tries to get the CSV file by either of the methods I mention, yet it won't work.

What's really annoying is, if I just change the file extension from .csv to .mp3 , the code works and Windows Media Player instantly opens and tries to play the file.

As soon as it's changed back to .csv, I get the file security problem!

Any other ideas?





"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> PERL v1.5 beta (FusionCharts)
 
The easiest way is with Group Policy.

Computer Configuration / Administrative Templates / Windows Components / Internet Explorer / Security FEATURES (?) / Restrict File Download /

It's also helpful to disable the information bar warning FEATURE (?) which is just below the above setting.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top