.net File Download on Mac only get .JPEG appended

55 views Asked by At

I've got a legacy app that allows upload and download of files. The files are stored on disc the files names in a SQL database. To allow duplicate files names from the users, the database store the user original file name and a unique name. The files are displayed in a .NET repeater with the command argument supplying both files names (original and unique). When the file is downloaded the code below serves up the file to the user with the original name.

All works fine on PC with Chrome, IE, FFox. For Mac user, they get FileName.ext.jpeg when they should be getting just FileName.ext

I'm not very well versed in Mac stuff. Is there something I can do to ContentType or Content-Dispositon to fix this for the few Mac users and not impact my large PC user base?

Here is the code to rename the file stored on the server with the original name:

LinkButton btn = (LinkButton)(sender);
string sURL = "";
string sFileName = btn.CommandArgument;

string sOriginalFileName = sFileName.Substring(0, sFileName.LastIndexOf("~"));
string sServerFileName = sFileName.Substring(sFileName.LastIndexOf("~") + 1); ;

sURL = sResourceRoot + "\\" + sServerFileName;

Response.ContentType = "image/jpeg";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + sOriginalFileName);
Response.TransmitFile(Server.MapPath(@"~/" + sURL));
Response.End();
1

There are 1 answers

0
Dean Goodman On

Generally, you should quote your filename in the Content-Disposition header -- see here. Note also that unexpected filename characters could play a role in your issue. It's probably worth using the built-in .NET ContentDispositionHeaderValue class to help create your header.

Try this - it should also be safe for all the other browsers you list.

Response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = sOriginalFileName };