0
這是下載單個文件的代碼。我需要提前如何從asp.net中的數據庫下載多個文件c#
這是下載單個文件的代碼。我需要提前如何從asp.net中的數據庫下載多個文件c#
這是下載多個文件的解決方案來下載單一的點擊多個文件的Zip文件夾本地機器
protected void DownloadFile(object sender, EventArgs e)
{
int id = int.Parse((sender as LinkButton).CommandArgument);
byte[] bytes;
string fileName, contentType;
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (MySqlConnection con = new MySqlConnection(constr))
{
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.CommandText = "select Name, Data, ContentType from tblFiles where [email protected]";
cmd.Parameters.AddWithValue("@Id", id);
cmd.Connection = con;
con.Open();
using (MySqlDataReader sdr = cmd.ExecuteReader())
{
sdr.Read();
bytes = (byte[])sdr["Data"];
contentType = sdr["ContentType"].ToString();
fileName = sdr["Name"].ToString();
}
con.Close();
}
}
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = contentType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
single sql command? –
上傳代碼在這裏做什麼? – Imad
我正在使用此上傳代碼上傳多個文件,但我可以從數據庫下載單個文件,但我想單擊一下即可下載所有文件 –