Download problem with spaces in filename

Discuss building things with or for the Mozilla Platform.
Post Reply
mohamed.arafath
Posts: 1
Joined: September 25th, 2013, 7:00 am

Download problem with spaces in filename

Post by mohamed.arafath »

Hi ,

I am Arafath . I am trying to download the uploaded file from commonshare path using ASP.NET.
i have my files with file name as " Fixed fhfgfhfhfghf). dfadasdasdasda. asdasdada. fgdfgdfgd. IssuesBuild.xlsx" . the problem here is IE and Chrome downloads the file with correct name with format. Mozilla truncates the words after the first space and remove the file format as well. dont know how to fix that .

Kindly help me to fix the issues.

below is the code .

string path = @"C:\Fixed (fhfgfhfhfghf).dfadasdasdasda.dasdasdada.fgdfgdfgd.IssuesBuild.xlsx";
file = new FileInfo(path);
if (file.Exists)
{
BinaryReader fs = new BinaryReader(file.OpenRead());
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(file.Name));
HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
HttpContext.Current.Response.ContentType = "application/octet-stream";
byte[] bite = fs.ReadBytes((int)file.Length);
fs.Close();
HttpContext.Current.Response.BinaryWrite(bite);
}


Reply me ASAP
User avatar
makaiguy
Posts: 16878
Joined: November 18th, 2002, 6:44 pm
Location: Somewhere in SE USA
Contact:

Re: Download problem with spaces in filename

Post by makaiguy »

Try replacing the space with the three characters %20 when specifying the URL in Firefox. (I suspect the other browsers are probably doing this automatically.)

See http://www.faqs.org/rfcs/rfc1738.html, and scroll down to the discussion of Unsafe characters.
Doug Wilson
Win10 64bit: FF 124.0.2 64bit, TB 102.12.0 32-bit ║ Android 13/10: FF 124.2.0/115.9.0 ║ No TB for Android available, dammit!
What a fool believes he sees, no wise man has the power to reason away - Doobie Brothers
harg
Posts: 9
Joined: November 8th, 2004, 3:12 am

Re: Download problem with spaces in filename

Post by harg »

This is a problem even with sites that do encode the spaces. For example, http://www.leevalleypark.org.uk/media/v ... 20Weir.pdf downloads as Ware with no file extension.

[Edit]: The forum hides the %20 section due to the length of the link, but check the URL -- it is the first download link at http://www.leevalleypark.org.uk/en/cont ... here-maps/ -- ending as /Maps/Ware%20to%20Dobbs%20Weir.pdf

I would not mind so much that it truncates the name, but losing the .pdf at the end is catastrophic -- it means that the file cannot even be displayed until it has been properly renamed.

- -

Currently testing in Aurora 29.0a2 but I previously had similar on other sites in FF 27 too.
Windows 7 pof 64 bit
Post Reply