I'm sending a file to the browser to be saved locally. This works fine in all browsers except Microsoft Edge, where it replaces the filename with a guid. The file has to be downloaded with a specific filename, is there an explanation or workaround for this problem? My answer "don't use Edge" will be rejected.
var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new ByteArrayContent(CreateFile(fileContents))
};
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = string.Concat(fileName, ".xlsx")
};
I had the same problem on Edge, when the user click to download a .ai file it opens automatically as a .pdf file rather than downloading the .ai file.
The ContentDisposition was correct and works very well on all Browsers, but seems that Edge was ignoring this header for some reason.
After long investigations and tryings I ended to 2 solutions:
- Always download your files as Zip files (this was not an option for me and I didn't find it acceptable specially on mobile devices)
- Add the download attribute to the download file link and make sure the attribute value has the file name. (this solved the problem on edge and works fine on all other browsers)
More about the attribute: https://davidwalsh.name/download-attribute
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With