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
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
sudharsan sPosted Jul 5, 2012, 4:16 AM
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, 4:11 AM
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);