The path you pass to the
WriteFile
method needs to be either the absolute physical path of the file on your server (eg:
C:\Path\To\Your\File.txt
), or the virtual path of the file on your site (eg:
~/path/to/your/file.txt
, or
/path/to/your/file.txt
, or
../path/to/your/file.txt
).
You are passing in a URL -
http ://test.b4live.com/path/to/your/file.txt
- which is not supported.
Try something like this:
string filePath = Request.MapPath(link.Text, Request.ApplicationPath, false);
Response.ContentType = ContentType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath));
Response.WriteFile(filePath);
Response.End();
Pay attention to the comment: You need to make sure that the file you're sending is one you want the user to be able to download. Otherwise, you could end up sending the contents of your
web.config
file, or the source code for your site.