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
我正在使用此上传代码上传多个文件,但我可以从数据库下载单个文件,但我想单击一下即可下载所有文件 –