1

I am passing a query string parameter containing file name.

default.aspx?file=Fame+ adlabs.xml (Fame+ adlabs.xml is the actual file name on server). The file name has "+" & also blank spaces.

When I check for file name from query string as follows:

   var fileName = Request.QueryString["file"];

The variable filename does not have a "+" in it. It reads as "Fame adlabs.xml" & hence I get a file not found exception. I cannot rename the xml files. Can someone please guide me into right direction.

Thanks

Ian
  • 29,380
  • 18
  • 66
  • 103
Robin
  • 273
  • 3
  • 20

2 Answers2

0

You should URL encode into your javascript before sending it :

var name = "Fame+ adlabs.xml";
var url = "default.aspx?file=" + encodeURIComponent(name);

Pay attention that following char won't work : ~!*()'

Deblaton Jean-Philippe
  • 10,809
  • 2
  • 49
  • 65
0

If you are trying to do it at the server in C#:

String FileName = "default.aspx?";

String FullURL = FileName + HttpUtility.UrlEncode("Fame + adlabs.xml");

String Decoded = HttpUtility.UrlDecode(FullURL);
Steve Wellens
  • 20,326
  • 2
  • 25
  • 66