日期:2014-05-18  浏览次数:20506 次

repeater控件下的LinkButton实现下载工呢过
用 OnCommand事件怎么没反应,错也不报  
 
C# code

  protected void DownLoadBtn_Command(object sender,CommandEventArgs  e)
    {
        if (e.CommandName == "DownLoad")
        {
            DataSet ds = bll_FileMan.CheckIsFile(RootID);
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                string path = Session["FolderPath"] + ds.Tables[0].Rows[0]["FileName"].ToString();
                FileInfo fi = new FileInfo(path);
                if (fi.Exists)
                {
                    Response.AddHeader("content-type", "application/x-msdownload");

                    Response.AddHeader("Content-Disposition", "attachment;filename="

                    + System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(fi.Name)));

                    Response.Flush();
                }
                FileStream streamFile = File.OpenRead((Session["FolderPath"] + "/" + ds.Tables[0].Rows[0]["FileName"].ToString()));

                byte[] byteFile = new byte[streamFile.Length];

                streamFile.Read(byteFile, 0, int.Parse(streamFile.Length.ToString()));

                Response.BinaryWrite(byteFile);

                Response.End();
            }
        }
    }



------解决方案--------------------
C# code

protected void DownLoadBtn_Command(object sender,CommandEventArgs  e)
    {
        if (e.CommandName.Equals("DownLoad"))
        {
            DataSet ds = bll_FileMan.CheckIsFile(RootID);
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                string path = Session["FolderPath"] + ds.Tables[0].Rows[0]["FileName"].ToString();
                FileInfo fi = new FileInfo(path);
                if (fi.Exists)
                {
                    Response.AddHeader("content-type", "application/x-msdownload");

                    Response.AddHeader("Content-Disposition", "attachment;filename="

                    + System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(fi.Name)));

                    Response.Flush();
                }
                FileStream streamFile = File.OpenRead((Session["FolderPath"] + "/" + ds.Tables[0].Rows[0]["FileName"].ToString()));

                byte[] byteFile = new byte[streamFile.Length];

                streamFile.Read(byteFile, 0, int.Parse(streamFile.Length.ToString()));

                Response.BinaryWrite(byteFile);

                Response.End();
            }
        }
    }

------解决方案--------------------
字符串比较 不要用"=="来做
------解决方案--------------------
字符串比较 不要用"=="来做