Reputation: 11
In my application I'm uploading a file which has Swedish characters in file name. It works fine. But when I try to download it, I get an error: "An invalid character was found in the mail header" ..Could you help regarding this Please see my code
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;
}
Upvotes: 1
Views: 1567
Reputation: 48240
Please try to encode the filename using HttpUtility.UrlPathEncode
.
http://msdn.microsoft.com/en-us/library/system.web.httputility.urlpathencode.aspx
Upvotes: 1