Solved

How do you escape ampersand in IE File Download dialog box?

Posted on 2008-10-20
10
858 Views
Last Modified: 2012-06-21
How do you escape ampersand in IE's "file download dialog box"?

I'm trying to download a file that has an ampersand on its file name (eg. "Batman & Robin.xls" )

IE File Download converts ampersand(&) to an underscore(_) (eg. "Batman _Robin.xls")

I tried escaping it with &&, but the file when downloaded also produces a double ampersand(&&)
0
Comment
Question by:niko_edralin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 8

Expert Comment

by:fcardinaux
ID: 22764768
Have you tried to use the Javascript encodeURIComponent() function http://www.w3schools.com/jsref/jsref_encodeURIComponent.asp ?
0
 
LVL 8

Expert Comment

by:fcardinaux
ID: 22764772
Go to http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_encodeURIComponent, type:

document.write(encodeURIComponent("Batman & Robin.xls"));

and you will get:

Batman%20%26%20Robin.xls
0
 
LVL 11

Expert Comment

by:Louis01
ID: 22764809
Replace the & with %26
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 8

Accepted Solution

by:
fcardinaux earned 125 total points
ID: 22764850
Louis01: if you had read my comments, you would have seen that my solution does exactly this. Moreover, it encodes all special characters, not just &.
0
 
LVL 11

Expert Comment

by:Louis01
ID: 22764862
fcardinaux: You are 100% correct. I usually open about 5 questions in different tabs. (This was the last one I got to.) My view on the Q was before you proposed your answer. I did not refresh before I posted my answer.
0
 

Author Comment

by:niko_edralin
ID: 22765039
I did both of your solutions. And the "file download dialog box" still <b>displays</b> "Batman _Robin.xls"

&& works great, but the downloaded file also has 2 ampersands "Batman && Robin.xls"
0
 

Author Comment

by:niko_edralin
ID: 22765177
This is the Java code that I'm using, hope it helps.


    private String getFileName() {
 
        String str=prefix+=" ("+_workbookSettings.getCode()+"-"+_workbookSettings.getDescription()+")";
 
        str=str.replaceAll(" ", "%20");//issue for i.e.7
        str=str.replaceAll("\\.", "%2e");
        str=str.replaceAll("&", "%26");
        return str+".xls";
    }
 
  public void finished(){
       ...
       ...
       ...
       resp.setContentType("application/vnd.ms-excel");
       resp.addHeader("content-disposition",
                                   "inline;    
       filename=encodeURIComponent(" + getFileName() + ")");
 
       workbook.write(out);
 
       out.flush();
       out.close();
 
       ...
       ...
    }

Open in new window

0
 
LVL 11

Assisted Solution

by:Louis01
Louis01 earned 125 total points
ID: 22765506
Try replacing the line
   str=str.replaceAll("&", "%26");
with
   str = str.replaceAll(/&/,"%26");
OR
   str = str.replaceAll(/&amp;/,"%26");
OR
   str = str.replaceAll(/\x26/,"%26");
----------------------
Alternatively, you could try removing the 3 str=str.replaceAll lines in getFileName. (If that works, the solution proposed by fcardinaux is the correct one.)
0
 

Author Comment

by:niko_edralin
ID: 23154859
Still doesn't work :(

anyway, I was able to force our QA to accept it as a bug of IE.
0
 

Author Closing Comment

by:niko_edralin
ID: 31508158
I didn't find the solution that I wanted. I'm just going to close this question and split the points to Louis01 and fcardinaux
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
isNaN issue on the Table input text 2 41
JSON help 8 46
Open new WPF windows - powershell 4 37
Add Log to powershell Script 14 29
In this post we will learn different types of Android Layout and some basics of an Android App.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

734 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