Reputation: 9081
I'd like to download a file in my ASP.NET application. I used this snippet:
try
{
string s = fichier.GetFichierUrlById(_id);
Response.ContentType = "application/" + Path.GetExtension(s);
Response.AppendHeader("Content-Disposition", "attachment; filename=" + s);
Response.TransmitFile(Server.MapPath("~/Downloads/"+s));
Response.End();
}
catch { }
In this example, I have the file setup.exe
, and I get an exception like The format of the given path is not supported.
What is the cause of this exception? How can I fix the code?
Upvotes: 0
Views: 253
Reputation: 5469
TransmitFile
would assume that there is a physical file in the downloads sub folder.
If that is not the case, then you'll need to do something like write the data into the output stream yourself.
Upvotes: 1
Reputation: 141
Check the value of S, and hence, the return value of "Server.MapPath("~/Downloads/"+s).
You might have some invalid characters in S which blow things out maybe?
Upvotes: 2