in asp.net:
<asp:LinkButton id="hj1" Text="Download" runat="server" OnClick="hj1_Click" ForeColor="blue" ToolTip="Click here to download file" ></asp:LinkButton>
in c#:
private void DownloadFile(string fname, bool forceDownload)
{
//string path = MapPath(fname);
//string path = fname; System.IO.Path.Combine(File Path, "jewel.xls");
string name = System.IO.Path.GetFileName(fname);
string ext = System.IO.Path.GetExtension(fname);
string type = "";
// set known types based on file extension
if (ext != null)
{
switch (ext.ToLower())
{
case ".htm":
case ".html":
type = "text/HTML";
break;
case ".txt":
type = "text/plain";
break;
case ".doc":
case ".rtf":
type = "Application/msword";
break;
}
}
if (forceDownload)
{
Response.AppendHeader("content-disposition", "attachment; filename=" + name);
}
if (type != "")
Response.ContentType = type;
Response.WriteFile(fname);
Response.End();
}
protected void hj1_Click(object sender, EventArgs e)
{
string fileName = "";
fileName = System.IO.Path.Combine(File Path, fName); //file path like "C://jewel.xls"
DownloadFile(fileName,true);
}
try in this way not exactly cause there's may b some spelling error but the logic is right
Please mark as answer if this helps u.