Hello friends,
I want to use link button for download. i want to give one link for download . if user click on this link then download will be start automatically ..
Reply me ASAP..
thanks in Advance
How to use link button for download
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


sudharsan s110 reputationPosted Jul 5, 2012, 12:16 AM EDT
click event funtion:
string URL = "your_url";
FileInfo fileInfo = new FileInfo(URL);
if (fileInfo.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Flush();
Response.WriteFile(fileInfo.FullName);
}
Posted Jul 5, 2012, 12:11 AM EDT
1)
const string fName = @"C:\testfile.txt"; //file should be available on the server
FileInfo fi = new FileInfo(fName);
long sz = fi.Length;
Response.ClearContent();
Response.ContentType = text/plain;
Response.AddHeader("Content-Disposition", string.Format("attachment; filename = {0}",System.IO.Path.GetFileName(fName)));
Response.AddHeader("Content-Length", sz.ToString("F0"));
Response.TransmitFile(fName);
Response.End();
2)
WebClient client = new WebClient();
client.DownloadFile(SourceFileName, destinationfilename);