C# 下载文件名中带有国际字符的文件

C# 下载文件名中带有国际字符的文件,c#,asp.net-mvc,C#,Asp.net Mvc,在我的应用程序中,我上传了一个文件名中有瑞典语字符的文件。它很好用。 但是当我试图下载它时,我得到了一个错误:“在邮件头中发现了一个无效字符”。你能帮我解决这个问题吗 请看我的密码 public ActionResult Download(Guid id) { var attachment = AttachmentService.GetAttachmentById(id); var cd = new ContentDisposition {

在我的应用程序中,我上传了一个文件名中有瑞典语字符的文件。它很好用。 但是当我试图下载它时,我得到了一个错误:“在邮件头中发现了一个无效字符”。你能帮我解决这个问题吗 请看我的密码

public ActionResult Download(Guid id)
{
   var attachment = AttachmentService.GetAttachmentById(id);
   var cd = new ContentDisposition
                {
                  FileName = Utility.GetCleanedFileName(((FileAttachment)attachment).FileName),
                  Inline = false,
                };

   var file = File("\\App_Data" +((FileAttachment)attachment).FilePath, "Application");

   Response.ClearHeaders();
   Response.Clear();
   Response.ContentType = file.ContentType;
   Response.AppendHeader("Content-Disposition", cd.ToString());

   var filePath = "\\App_Data" + ((FileAttachment) attachment).FilePath;

   Response.WriteFile(filePath);
   Response.End();

   return file;
}

请尝试使用
HttpUtility.UrlPathEncode
对文件名进行编码


请尝试使用
HttpUtility.urlpathcode
对文件名进行编码


能否提供一个文件名示例?另外,您正在测试哪个浏览器?能否提供一个文件名示例?另外,您正在测试哪个浏览器?