当前位置: 代码迷 >> ASP.NET >> repeater控件下的LinkButton实现下载工呢过,该如何处理
  详细解决方案

repeater控件下的LinkButton实现下载工呢过,该如何处理

热度:4613   发布时间:2013-02-25 00:00:00.0
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();            }        }    }
------解决方案--------------------------------------------------------
字符串比较 不要用"=="来做
------解决方案--------------------------------------------------------
字符串比较 不要用"=="来做
  相关解决方案