0

On our asp.net project, the users can download some files. Here's the code i'm using for the download part:

String localUpload = ConfigurationManager.AppSettings["PastaEditais"].ToString();                    
String nomeArquivo = licitacao.getEdital();                
FileInfo fi = new FileInfo(localUpload + nomeArquivo);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + licitacao.getEdital());
Response.AddHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(fi.FullName);
Response.End();

IF the filename doesn't have any white spaces on it, it appears normally.

For example: if the name is ATI_06-07-2014.txt, it will appear just like this. But if it has white spaces, only part of the name is shown on the download dialog box.

ATI 06-07-2014.txt will be shown only as 'ATI'

How can i fix this?

Joao Victor
  • 1,111
  • 4
  • 19
  • 39

1 Answers1

1

Add quotes to the filename:

Response.AddHeader("Content-Disposition", "attachment; filename=\"" + licitacao.getEdital() + "\"");
Todd Menier
  • 37,557
  • 17
  • 150
  • 173