buda
buda

Reputation: 2372

File Download Dialog

I have one problem.

In ASP.NET application i created link to some document, document name is stored in database and when user click on link File Download dialog appears.

Problem occurs when file name is Serbian Cyrilic, File Download dialog shows file name with some strange characters. See image

File download file name strange characters

Whene i use HtmlEncode for file name IE works fine (shows right file name), but then problem is in FireFox.

Thanks.

Upvotes: 3

Views: 960

Answers (1)

Marek Kwiendacz
Marek Kwiendacz

Reputation: 9844

You have to encode non-AscII characters. I'm using this method:

    public static string URLEncode(string tekst)
    {
        byte[] t = Encoding.UTF8.GetBytes(tekst);
        string s = "";
        for (int i = 0; i < t.Length; i++)
        {
            byte b = t[i];
            int ib = Convert.ToInt32(b);
            if (ib < 46 || ib > 126)
            {
                s += "%" + ib.ToString("x");
            }
            else
            {
                s += Convert.ToChar(b);
            }
        }
        return s;
    }  

And check if you have to encode it - it should work then in IE and FF:

if (Page.Request.Browser.IsBrowser("IE"))  
fileName = URLEncode(fileName);

Upvotes: 2

Related Questions