string fileName;
        LinkButton tb = (LinkButton)sender;//按钮
        GridViewRow gv = (GridViewRow)tb.Parent.Parent;//数据视图对象
        fileName = ((Label)GridView1.Rows[gv.RowIndex].Cells[0].FindControl("Label1")).Text;
        string filePath = Server.MapPath(".") + "\\Attachment\\" + fileName;//路径
        FileInfo fileInfo = new FileInfo(filePath);
        Response.Clear();
        Response.ClearContent();
        Response.ClearHeaders();
        Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
        Response.AddHeader("Content-Length", fileInfo.Length.ToString());
        Response.AddHeader("Content-Transfer-Encoding", "binary");
        Response.ContentType = "application/octet-stream";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
        Response.WriteFile(fileInfo.FullName);
        Response.Flush();
        Response.End();
上面的代码用来下载文件,为什么有时候下载的对话框会一闪而过,有时候会下载代码所在的页面,有时候会提示无法下载,有时候能正常下载