Recommend a filename with space chars for download "Save As..." dialog

  • Thread starter Thread starter deerchao
  • Start date Start date
D

deerchao

I used these codes to provide a default "Save As" filename for
browsers:

Response.AppendHeader("Content-Disposition",
"attachment; filename=" + fileName);
Response.ContentType = "application/octet-stream";

But if there are space chars in the file name, FireFox would split the
recommed file name, and use the first part only. For example, if
fileName=="aaa bbb.watever", then the "Save As" dialog will take "aaa"
as the filename.

And if there are more than one dots(char '.'), IE will add a "[1]"
before the first dot char. For example, if
fileName=="aaa.bbb.whatever", IE will show "aaa[1].bbb.whatever".

For some reason, I'd like to make these default file names exactly as
what I recommeded, Is there any way to do this?

Thanks!

Note: I tried UrlEncode and HtmlEncode the fileName in HTTP headers,
but none of them worked.
 
I used these codes to provide a default "Save As" filename for
browsers:

Response.AppendHeader("Content-Disposition",
"attachment; filename=" + fileName);
Response.ContentType = "application/octet-stream";

But if there are space chars in the file name, FireFox would split the
recommed file name, and use the first part only. For example, if
fileName=="aaa bbb.watever", then the "Save As" dialog will take "aaa"
as the filename.

And if there are more than one dots(char '.'), IE will add a "[1]"
before the first dot char. For example, if
fileName=="aaa.bbb.whatever", IE will show "aaa[1].bbb.whatever".

For some reason, I'd like to make these default file names exactly as
what I recommeded, Is there any way to do this?

Thanks!

Note: I tried UrlEncode and HtmlEncode the fileName in HTTP headers,
but none of them worked.

OK, I figured out the first problem:
Surround the filename with double quotes.
Now FireFox works perfectly, but IE still adds [1] before the first
dot char.
 
Ajay Lonare said:
HI..

I am facing the same problem when trying to download file by using C# code. I used filename MyPlayer.pda.xml but when downloading it display in save as dlg box = Myplayer[1].pda.xml.

Is there anyone know abut it why it is happning?

From http://www.developmentnow.com/g/36_...-space-chars-for-download-Save-As--dialog.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com/g/

As I for some reason am unable to see the original poster's post, I wonder
if this is a case of Win32 vs NTFS file system. NTFS allows more characters
in filenames than Win32 supports, for instance white space characters at the
end of the filename. If so, then .Net only supports Win32 style filenames.
There may be a change in the future, but as far as I know, that won't happen
in .Net 4.0.
 
Could it be suggesting a unique name because a file with that name already
exists in the target folder?
 
Back
Top