Search code examples
c#unicodeurldecode

How to decode a url with accents in C#


I've been trying to decode %E9(é).

WebUtility.HtmlDecode("%E9")

doesn't work. It puts a ? sign instead of a é.


Solution

  • I've tested this and found that HttpUtility.UrlDecode("%E9") returns question mark that You mentioned. It seems that it You have to manually specify appropriate encoding for this to work correctly with %E9 encoded value.

    You can try:

    HttpUtility.UrlDecode("%E9", System.Text.UnicodeEncoding.Default);
    

    or

    HttpUtility.UrlDecode("%E9", System.Text.UnicodeEncoding.UTF7);
    

    Both should return the character decoded as You expected.