当文件名为“Algunas MARCAS que nos acompañan”时,ASP.NET MVC 在我尝试下载该文件时引发 System.FormatException
。但如果文件名为“Asistente de Gerencia Comercial”,则不会。
我猜这是因为与 UTF-8
编码有关,但我不知道如何对该字符串进行编码。
如果我是对的,我如何用 UTF-8
编码对字符串进行编码?如果我不对,我的问题是什么?
最佳答案
我这样编码文件名以供下载,
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename= " + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
关于c# - 如何对文件名进行编码以供下载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1598373/