2

I have a javascript code like this :

function OnRequestComplete(result) {
        // Download the file
        //Tell browser to open file directly
        alert(result);
        var requestImage = "Handler.ashx?path=" + result;
        document.location = requestImage;
}

and Handler.ashx code is like this :

public void ProcessRequest(HttpContext context)
{
    Context = context;
    string filePath = context.Request.QueryString["path"];
    filePath = context.Server.MapPath(filePath);
}   

In filePath we don't have any + signs (spaces instead).
How can I solve this issue ?
Why does Request.QueryString["path"] converts all + signs to spaces ?

HoLyVieR
  • 10,985
  • 5
  • 42
  • 67
SilverLight
  • 19,668
  • 65
  • 192
  • 300
  • check this answer: http://stackoverflow.com/questions/123994/querystring-malformed-after-urldecode/124027#124027 – Davide Piras Oct 23 '11 at 16:59
  • Querystrings have their own syntax and reserved chars. Encode you filename yourself. – H H Oct 23 '11 at 16:59

1 Answers1

4

When you correctly encode the query string a space becomes + and + becomes %2B. The process of decoding does the reverse, which is why your + gets turned into a space.

The problem is that you didn't encode the query string, and that means it gets decoded incorrectly.

var requestImage = "Handler.ashx?path=" + encodeURIComponent(result);
Community
  • 1
  • 1
Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452