?
Solved

Download Link

Posted on 2005-04-12
10
Medium Priority
?
293 Views
Last Modified: 2010-04-01
Hey,
I've a website that creates files dynamically from a database and then creates a link to the created file so that someone can click on the link to download the file. The file I'm making is a .csv file and it's created fine. The problem is that when someone clicks on the link it just opens the file in the browser. I want to be able to get the usual popup of opening the file (using excel) or saving it,
help badly needed

aka_damo
0
Comment
Question by:aka_damo
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 92

Expert Comment

by:objects
ID: 13768464
what content type are you using?
should be something like: application/vnd.ms-excel
0
 

Author Comment

by:aka_damo
ID: 13768480
objects,
All I have is a jsp page with the following

Click <a href="report.csv">HERE</a> to Download Report

report.csv is stored in the root directory of the application
0
 
LVL 92

Expert Comment

by:objects
ID: 13768511
try:

<a href="report.csv" type="application/vnd.ms-excel">HERE</a>
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 13768530
well from a href.. its really not in your hands.... its in the browser's hand how he wants to handle a particular type of file.
You might try to make fool of the browser by doing
<a href="report.csv" type="application/octent-stream>HERE</a>
or
<a href="report.csv" type="application/downloadit>HERE</a>

and see if browser likes it...
0
 

Author Comment

by:aka_damo
ID: 13768540
Tried that, still not working. Just doing the same thing as before
0
 
LVL 92

Expert Comment

by:objects
ID: 13768556
May be dependant on the browser settings, ie. how it is configured to handle csv files.
0
 

Author Comment

by:aka_damo
ID: 13768570
I've tried it for every type of file but it's still not working. I tried it for .xls files that I created with excel and It still won't work
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 13768571
okay rename your file to be as report.tst... and see what it does
0
 

Author Comment

by:aka_damo
ID: 13768594
Did that, tried .tst and .txt, both give me the same result. If i try and open a proper excel file the browser just prints out the binary junk that notepad would show
0
 

Accepted Solution

by:
liamgannon earned 600 total points
ID: 13786673
I've seen this before, internet explorer is getting a bit too big for it's boots and is trying to open up every file type itself. One thing that IE can't open is zip files. Try zipping the file after you create it and let your jsp page point to the zip file and not the csv file. it should pop up with the option of opening the zip file or downloading it(provided you have winzip installed or are running xp). Try the following code to zip your file

// These are the files to include in the ZIP file
    String[] filenames = new String[]{"filename1", "filename2"};
   
    // Create a buffer for reading the files
    byte[] buf = new byte[1024];
   
    try {
        // Create the ZIP file
        String outFilename = "outfile.zip";
        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
   
        // Compress the files
        for (int i=0; i<filenames.length; i++) {
            FileInputStream in = new FileInputStream(filenames[i]);
   
            // Add ZIP entry to output stream.
            out.putNextEntry(new ZipEntry(filenames[i]));
   
            // Transfer bytes from the file to the ZIP file
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
   
            // Complete the entry
            out.closeEntry();
            in.close();
        }
   
        // Complete the ZIP file
        out.close();
    } catch (IOException e) {
    }
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You have missed a phone call. The number looks like it belongs to the bunch of numbers which your company uses. How to find out who has just called you?
In-App Messaging has revolutionized the way we look at marketing. It has also changed the way we use Apps. If In-App Messaging is used well then you will find that it can drive a lot of traffic to specific areas of your site. It also helps to improv…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
Suggested Courses

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question