Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# fileName display with spaces trouble

Tags:

c#

file

file-io

Suppose I have a report Name as :

string reportName = "Facebook Network Performance Summary Report (By Region, By Content)";

and I would like to display that file name as excel

the below is my code to export the file

Response.AddHeader("Content-Disposition", "attachment; filename=" reportName + ".xls");
Response.AddHeader("Content-Length", l.ToString());
Response.ContentType = "application/vnd.ms-excel";
Response.BinaryWrite(f);

Unluckily, thewhen reading the first space of my reportName, it only shows Facebook and no else.

Is there any wexisting API for ASP.NET or other methods to handle the spaces of fileNAme ?

like image 379
Raju yourPepe Avatar asked Dec 19 '25 10:12

Raju yourPepe


2 Answers

Try wrapping the filename in double quotes.

 string filename = reportName + ".xls";
 Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
like image 179
Kapil Khandelwal Avatar answered Dec 21 '25 00:12

Kapil Khandelwal


You need to wrap the filename in quotes:

Response.AddHeader("Content-Disposition", "attachment; filename=\"" + reportName + "\".xls");
like image 29
aquinas Avatar answered Dec 21 '25 00:12

aquinas