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);
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?