我在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();
}
}
}
{
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();
}
}
}
...全文
相关推荐
C#圆形按钮,非常漂亮动态
C#圆形按钮,非常漂亮动态 Button,有源代码和例子,这是网上很少有的,兄弟们快下载呀!
C# winform编程中响应回车键的实现代码
主要介绍了C# winform编程中响应回车键的实现代码,既在窗口上响应回车键事件的方法,需要的朋友可以参考下
点不中的按钮
c#源码,奉献出来给大家学习一下,还是蛮实用的,推荐下载。
C# --ObjectArx永久反应器和临时反应器例子.rar
C# --ObjectArx永久反应器和临时反应器例子
C#+WPF上位机开发课程(模块化与反应式编程)
给大家分享一套课程——C#+WPF上位机开发课程(模块化与反应式编程)。 WPF是微软新一代图形系统,运行在.NET Framework 3.0及以上版本下,为用户界面、2D/3D 图形、文档和媒体提供了统一的描述和操作方法。基于DirectX 9/10技术的WPF不仅带来了前所未有的3D界面,而且其图形向量渲染引擎也大大改进了传统的2D界面,比如Vista中的半透明效果的窗体等都得益于WPF。



