请各位大侠帮帮忙了,这样写为什么实现不了?
本人用fileupload控件做了一个上传的页面。运行成功后能将压缩文件上传到项目根目录的upload文件夹中,同时将上传的文件名称,大小,类型等信息保存在一个为
t_upload的数据表中。
然后我又用GridView做了一个页面能显示上传的压缩文件的各项信息,并在GridView中添加了一个ButtonField列作为下载按钮。
我在GridView中增加了一个GridView1_RowCommand的事件
下面是我在该事件中的代码:
string sqlconn = "Data Source=890A81AF51784ED;Initial Catalog=lele;Integrated Security=True ";
SqlConnection dconn = new SqlConnection(sqlconn);
SqlCommand dcmd = new SqlCommand();
dcmd.Connection = dconn;
dcmd.CommandText = "select filename from t_upload ";
dconn.Open();
SqlDataReader dr = dcmd.ExecuteReader();
while (dr.Read())
{
///get the file
string filepath = Server.MapPath( "~/upload/ "+dr[ "filename "].ToString ()+ " ");
///get the file stream to get the file length
System.IO.FileStream fs = new System.IO.FileStream(filepath, System.IO.FileMode.Open);
///set the content type
Response.ContentType = "application/zip ";
///set Content-Disposition
Response.AppendHeader( "Content-Disposition ", "attachment; filename= "+dr[ "filename "].ToString ()+ " ");
///get the file size
long filesize = fs.Length;
fs.Close();
///set the content length to the size of the file
///this will chop off the extra junk that may be sent by the ASP.NET runtime along with your file