我在C#里面写了下载文件的代码,用的gridview的command按钮,但是点击下载后没有反应。有没有大侠帮帮小弟,小弟万分感谢。
protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "报告")
{
int rowIndex = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView3.Rows[rowIndex];
string name = ((Label)(row.Cells[1].Controls[0]).FindControl("Label33")).Text.ToString().Trim();
string time1 = DateTime.Now.ToString("yyyy-MM");
string filename = "课题进展报告\\" + time1 + "-" + name + ".pdf";
string url = Server.MapPath(filename);
string filename = "课题进展报告\\" + time1 + "-" + name + ".pdf";
string url = Server.MapPath(filename);
if (File.Exists(url))
{
FileInfo fileInfo = new FileInfo(Server.MapPath(filename));
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8) + "\"");
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType = "application/octet-stream";
Response.WriteFile(fileInfo.FullName);
Response.Flush();
Response.End();
}
}
}