用    OnCommand事件怎么没反应,错也不报   
 
  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();
            }
        }
    }

解决方案 »

  1.   


    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();
                }
            }
        }