O
O
one__for__one2016-11-29 13:53:03
ASP.NET
one__for__one, 2016-11-29 13:53:03

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();

Found the code, but it only works in EI, for mozilla firefox or is there something similar for chrome?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Nemiro, 2016-11-29
@one__for__one

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 question

Ask a Question

731 491 924 answers to any question