Ext.Net中,文件下载。

传参到另一个页面(~/Service/DownLoad.aspx)

 

 /// <summary>
    /// 下载附件按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbnDownloadWork_Click(object sender, EventArgs e)
    {
        try
        {
            int pid = Convert.ToInt32(Request.QueryString["pid"]);
            MC_WORK_TASKACCESSORY GetAcessoryInfo = TaskService.GetTaskAcessoryByID(pid);
            string name = GetAcessoryInfo.DESCRIPTION;
            string Path = GetAcessoryInfo.ACCESSORYURL;

            string fileName = name;//客户端保存的文件名 
            string filePath = Server.MapPath(Path);//路径

            X.Redirect("~/Service/DownLoad.aspx?filename=" + fileName + "&filepath=" + filePath); 
        }
        catch
        {
            //提示信息:文件下载失败
            X.Msg.Alert("提示信息", "附件下载失败!").Show();
        }
    }
 protected void Page_Load(object sender, EventArgs e)
    {
        string filename = Request.QueryString["filename"];
        string filepath = Request.QueryString["filepath"];
        DownloadFile(filename, filepath);
    }

    /// <summary>
    /// 文件下载
    /// </summary>
    /// <param name="filename">文件名</param>
    /// <param name="filepath">文件路径</param>
    protected void DownloadFile(string filename, string filepath)
    {
        Response.Clear();
        Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.Default));
        Response.ContentType = "application/octet-stream";
        Response.TransmitFile(filepath);
        Response.End();
    }

 

posted @ 2013-05-16 09:54  陈海波  阅读(384)  评论(0编辑  收藏  举报