I have Url with space and would like to replace spaces with %20(escape them). UrlPathEncode should do that but it do not works on url below which has spaces. Can someone explain why it is not working?
System.Web.HttpUtility.UrlPathEncode("http://a1.quickcatchlabs.com/phototemplates/football_blimp_1.html?i_url=http://lh3.ggpht.com/yf5lVBB_WNBvBHT1HoIzY1SG0-PY5zRCobP3vBacuSk9N346F7CeAIRSFOltR6ZC1-yf-MNKAcAd7bAZ_A=s612-c&i_name=Patriots vs Redskins&i_venue_name=Gillette Stadium &i_venue_address=Foxborough , MA&d_Score_0=34&d_Score_1=27&d_Period_0=Final&p_name_0=Patriots &p_name_1=Redskins");
As the name implies, UrlPathEncode encodes the path. Just the path, not the query portion of the URL. If you add a space to path and run that code again, you will see that the space in the path portion is replaced by a
%20, but the spaces in the query portion are not.If you replace the call to
UrlPathEncodewith one to Uri.EscapeUriString, it will correctly encode the entire URL, not just the path.