Answer the question
In order to leave comments, you need to log in
How to download a file with a space in its name?
Hello.
ASP.NET web forms.
string FileName = listID[i].ToString();
FileInfo file = new FileInfo(FileName);
if (file.Exists)
{
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "text/plain";
response.AddHeader("Content-Disposition", "attachment; filename=" + file.FullName + ";");
response.TransmitFile(file.FullName);
response.Flush();
response.End();
Answer the question
In order to leave comments, you need to log in
1. Try putting the filename in quotes.
2. The FullName property will contain the full name of the file, including the path. In this case, it is better to use the Name property (just the file name, without the location path).
response.AddHeader("Content-Disposition", "attachment; filename='" + file.Name + "';");
// или
// response.AddHeader("Content-Disposition", "attachment; filename=\"" + file.Name + "\";");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question