Iam在提名门户上工作。用户提交他们的提名和一些附件。每个提名的附件数量可能在3到10之间。因此,对于每一次提名,评估人员必须每次下载10个文件,这非常紧张。所以我想提供一个选项,一次下载与提名有关的所有附件作为Zip文件。我能够一次下载单个文件。请为我提供一个解决方案,一次下载多个文件以及一些示例代码片段。以下是我用于下载文件下载的单个文件 的代码。我将文件内容存储为数据库中的二进制文件使用C从数据库下载多个文件
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 (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select Name, Data, ContentType from tblFiles where [email protected]";
cmd.Parameters.AddWithValue("@Id", id);
cmd.Connection = con;
con.Open();
using (SqlDataReader 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();
}
您需要格式化您的代码。 – artm 2014-10-01 04:34:01
实际问题是什么?如何创建一个zip文件?你有没有尝试过一些东西?你尝试谷歌,并没有找到解决方案? – 2014-10-01 07:08:12
您好Kanavos我的实际问题是如何从数据库一次下载多个文件。压缩是第二优先。即使我能够将所有文件存储在文件夹中,那也很好。我使用了Google,但我没有找到合适的解决方案。 Google中的每个解决方案都基于获取托管在服务器中但不在数据库中的一组文件,这与我的要求完全不同 – shabareesh 2014-10-01 07:17:26