Choose a location:
posted 2/18/2013 by Raghav Khunger
While working with transmitting files via server side was not working when filename was having space in it. I was using the following code:
var physicalFile = new FileInfo(path); if (physicalFile.Exists) { context.Response.ClearContent(); context.Response.Clear(); context.Response.ContentType = "text/plain"; context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0};", fileName)); context.Response.TransmitFile(path); context.Response.Flush(); context.Response.End(); }
The issue was with this line:
context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0};", fileName));
I found the solution at the following documentation which suggests to use quotes around the file names. I did the same and changed the above piece of code to :
context.Response.AddHeader("Content-Disposition", string.Format("attachment;filename=\"{0}\"", fileName));
And my issue was fixed after that.
What kind of email newsletter would you prefer to receive from CodeAsp.Net? 18