You can't specifically save the file if the user clicks on a link: the browser will obey whatever rules the user has set up, including any which require a confirmation.
If you mean "how do I give a user a link to click on, and it downloads a file?" then it depends on a number of factors:
1) Is the file in an available folder relative to the website? If so, then you can just give a line to the file:
<a href="http://MyDomain.com/folder/file.txt">Click here to download!</a>
2) Is the file stored in a database? If so, then give a link similar to the above, but with a file reference via an ASPX page:
<a href="wm5ftdl.aspx?file=2552129f-4629-4432-9de3-8177870d81be" target="_blank">Click here to download!</a>
Then in the page, retrieve the data from the DB:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="wm5ftdl.aspx.cs" Inherits="wm5ftdl" %>
<%
string guid = Request.QueryString["file"];
string fileName = "ERROR";
byte[] data = new byte[] { 0, 0, 0, 0 };
string strCon = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DownloadDatabase"].ConnectionString;
using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(strCon))
{
con.Open();
string strcmd = "SELECT [iD] ,cn.[fileName],[description] ,[dataContent] ,[version] " +
"FROM dlContent cn " +
"WHERE cn.iD=@ID";
using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(strcmd, con))
{
cmd.Parameters.AddWithValue("@ID", guid);
using (System.Data.SqlClient.SqlDataReader r = cmd.ExecuteReader())
{
if (r.Read())
{
fileName = (string) r["filename"];
data = (byte[]) r["dataContent"];
}
}
}
}
Response.Clear();
Response.AddHeader("Cache-Control", "no-cache, must-revalidate, post-check=0, pre-check=0");
Response.AddHeader("Pragma", "no-cache");
Response.AddHeader("Content-Description", "File Download");
Response.AddHeader("Content-Type", "application/force-download");
Response.AddHeader("Content-Transfer-Encoding", "binary\n");
Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
Response.BinaryWrite(data);
Response.End();
%>
There is nothing much in the .CS file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class wm5ftdl : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}