首页 新闻 会员 周边

非常严重的问题。。。。

0
悬赏园豆:30 [已解决问题] 解决于 2012-09-22 09:36
protected void LinkButton1_Click1( object sender , EventArgs e )
        {
            int row = ( (GridViewRow)( (LinkButton)sender ).NamingContainer ).RowIndex;
            string wenname = subll.getgnamebyid( Convert.ToInt32( grshow.Rows[row].Cells[0].Text ) );
            string filename = Server.MapPath( "~/" + subll.getway( Convert.ToInt32( grshow.Rows[row].Cells[0].Text ) ) );
            DownLoad( wenname , filename );
        }
        private void DownLoad( string strName , string strPath )
        {
            string fileName = strName;//客户端保存的文件名
                    FileStream fs = new FileStream( strPath , FileMode.Open );
            byte[] bytes = new byte[(int)fs.Length];
            fs.Read( bytes , 0 , bytes.Length );
            fs.Close( );
            Response.ContentType = "application/octet-stream";
            //通知浏览器下载文件而不是打开
            Response.AddHeader( "Content-Disposition" , "attachment;  filename=" + HttpUtility.UrlEncode( fileName , System.Text.Encoding.UTF8 ) );
            Response.BinaryWrite( bytes );
            Response.Flush( );
            Response.End( );
        }

点击linkbutton老是下载自己的这个aspx页面 不知道怎么回事。谷歌  火狐 没问题 求解释 ie8.。。什么的都有问题

隔壁王叔的主页 隔壁王叔 | 初学一级 | 园豆:4
提问于:2012-08-30 09:57
< >
分享
最佳答案
0
if (e.CommandName == "xiazai")
        {
            String fileName = e.CommandArgument.ToString();
            if (fileName != "")
            {
                //获得文件的存储路径               
                string path = Server.MapPath(fileName);
                System.IO.FileInfo file = new System.IO.FileInfo(path);
                if (file.Exists)
                {
                    Response.Clear();
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
                    Response.AddHeader("Content-Length", file.Length.ToString());
                    Response.ContentType = "application/octet-stream";
                    Response.Filter.Close();
                    Response.WriteFile(file.FullName);
                    Response.End();
                }
                else
                {
                    CommonFunc.showMessage(this.Page, "文件不存在");
                    //Response.Write("<script>alert('文件不存在');</script>");
                }
            }

试试这个,是在gridview里用的

收获园豆:10
羽商宫 | 老鸟四级 |园豆:2490 | 2012-08-30 11:03

用这种方法试过 也是同样的效果 不知道怎么回事呢

隔壁王叔 | 园豆:4 (初学一级) | 2012-08-30 13:06

@小 莫: Response.Clear();这句话用了没??

羽商宫 | 园豆:2490 (老鸟四级) | 2012-08-30 13:09
其他回答(6)
0

你调试一下看看你的filename是什么?

收获园豆:5
田林九村 | 园豆:2367 (老鸟四级) | 2012-08-30 10:07

路径没问题。。。调试过的

支持(0) 反对(0) 隔壁王叔 | 园豆:4 (初学一级) | 2012-08-30 10:49

@小 莫: 把linkbutton换成button试试? ^-^

支持(0) 反对(0) 田林九村 | 园豆:2367 (老鸟四级) | 2012-08-30 10:52
0
先要Response.Clear()
收获园豆:5
向往-SONG | 园豆:4853 (老鸟四级) | 2012-08-30 10:29
0

不行,就打开一个新的链接下载就行了

收获园豆:2
chenping2008 | 园豆:9836 (大侠五级) | 2012-08-30 12:57
0

能下载就行了

收获园豆:3
慧☆星 | 园豆:5640 (大侠五级) | 2012-08-30 15:44
0

报文头里面添加了东西不要将报文头作为输出响应流输出出去吗?

收获园豆:5
ajie1166 | 园豆:249 (菜鸟二级) | 2012-09-05 23:59
0

浏览器导致额 本身代码没问题

隔壁王叔 | 园豆:4 (初学一级) | 2012-09-22 09:35
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册