Escape characters in URL in vb.net

  • Thread starter Thread starter graphicsxp
  • Start date Start date
G

graphicsxp

Hi,
I've got a url that looks like that :

http://www.myurl.net/Drops 10% - News.doc

Obviously to be properly interpreted by browsers, special characters
should be converted (% -> %25 and spaces to %20)

Unfortunately I can't seem to find the right function in vb.net to do
that.... I've tried Server.UrlEncode which converts to a lot of crap,
and HttpUtility.UrlEncode which doesn't do it properly either...

Anyone knows how to do that ? Can't be that hard :(

Thanks
 
I've got a url that looks like that :

http://www.myurl.net/Drops 10% - News.doc

Obviously to be properly interpreted by browsers, special characters
should be converted (% -> %25 and spaces to %20)

Unfortunately I can't seem to find the right function in vb.net to do
that.... I've tried Server.UrlEncode which converts to a lot of crap,
and HttpUtility.UrlEncode which doesn't do it properly either...

Anyone knows how to do that ? Can't be that hard :(

What makes you think they're not working properly? Bear in mind that
you shouldn't be passing in the first part of the URL - just the "Drops
10% - News.doc" into UrlEncode.
 
What makes you think they're not working properly? Bear in mind that
you shouldn't be passing in the first part of the URL - just the "Drops
10% - News.doc" into UrlEncode.

HttpUtility.UrlEncode encodes the url as : Drops+10%25+-+Gulf
+News.doc

That doesn't work in IE or Firefox. Why does it encode spaces with
pluses ??! I can understand in the case of a querystring, but here
it's a url used as a simple link in my page...
 
HttpUtility.UrlEncode encodes the url as : Drops+10%25+-+Gulf
+News.doc

That doesn't work in IE or Firefox. Why does it encode spaces with
pluses ??! I can understand in the case of a querystring, but here
it's a url used as a simple link in my page...

Hmm. I tried using HttpUtility.UrlPathEncode instead, as it's a path
that you need to encode.

A quick test shows that working slightly better:
Drops10%%20-%20News.doc

.... but it's not encoding the original % now. I've no idea why.

Admittedly I'd try to avoid having such characters in paths to start
with, but that *looks* like a bug to me.
 
Hmm. I tried using HttpUtility.UrlPathEncode instead, as it's a path
that you need to encode.

A quick test shows that working slightly better:
Drops10%%20-%20News.doc

... but it's not encoding the original % now. I've no idea why.

Admittedly I'd try to avoid having such characters in paths to start
with, but that *looks* like a bug to me.

Well considering the files are sent to me by clients I can't really
ask them not to put this kind of signs in their filenames.... although
I would not to that myself.
Yeah I've noticed that too with URLPathEncode.... I think it's a bug
as well, but considering .net 2.0 has been around for 3 years, I just
can't believe no one has come across that before and fixed the issue !
Anyway I can't wait for Microsoft to make a move so I;ve used a good
old-fashioned String.Replace....
 
Back
Top