Click here to Skip to main content
13,860,665 members
Rate this:
Please Sign up or sign in to vote.
Hi all,

I have a small code that lists a directory on a server to a ListView. My problem is that if a filename contains foreign characters or maybe spaces, the characters are shown in 'web-like' format (space = %20, etc). The URL from I'm listing the directory is a HTTPS url! My code is:

url = "https://myaddress/directory/";
Uri uri = new Uri(url);
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);//it is needed because of the HTTPS
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
HttpWebResponse response = null;
response = (HttpWebResponse)request.GetResponse();
Encoding encoding = Encoding.GetEncoding("UTF-8");
StreamReader reader = new StreamReader(response.GetResponseStream(), encoding);
string html = reader.ReadToEnd();

I tried I think everything after the GetResponseStream part, found by google. Tried to add the followings, but no success:

request.ContentType = "text/html; charset=UTF-8";
request.Headers.Add(HttpRequestHeader.AcceptCharset, "UTF-8");

Of course I don't want to solve this problem in this ugly way:

html = html.Replace("%20", " ")
                        .Replace("%C3%81", "Á")
                        .Replace("%C3%A1", "á")
                        .Replace("%C3%89", "É")
                        .Replace("%C3%A9", "é")
                        .Replace("%C3%8D", "Í")
                        .Replace("%C3%AD", "í")
                        .Replace("%C3%93", "Ó")
                        .Replace("%C3%B3", "ó")
                        .Replace("%C3%96", "Ö")
                        .Replace("%C3%B6", "ö")
                        .Replace("%C5%90", "Ő")
                        .Replace("%C5%91", "ő")
                        .Replace("%C3%9A", "Ú")
                        .Replace("%C3%BA", "ú")
                        .Replace("%C3%9C", "Ü")
                        .Replace("%C3%BC", "ü")
                        .Replace("%C5%B0", "Ű")
                        .Replace("%C5%B1", "ű");

Any idea?
Updated 18-Sep-15 0:06am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can use HttpServerUtility.UrlDecode(myUrl) provided in System.Web namespace
DoomMaker79 21-Sep-15 4:14am
i've already tried it, not working... :( maybe I tried it in wrong way. can you please complete the code above with your suggestion?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.190214.1 | Last Updated 18 Sep 2015
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100