showmodaldialog弹出的窗口里,不能实现文件的下载解决方案

在showmodaldialog弹出的窗口里,不能实现文件的下载啊?
但是不用showmodaldialog时,页面是可以实现下载的。

大家有没有遇到同样的问题,怎么解决的!!

===============================================================================

方案一:
以前代码中的<base target="_self">修改为:

<iframe id="download" name="download" height="0px" width="0px"></iframe>
< base target="download">

但是这种方案会在下载文件或图片时弹出一个空白窗口。

且会影响其他按钮操作。

 

方案二:
下载按钮按下,在服务器端,将文件先下载到服务器端,然后将文件名返回到页面,在页面加一段JavaScript代码,
在javaScript中再次提交页面,提交时文件名被提交,提交到一个servlet中,servlet中边读取刚在服务器端下载的文件,然后下载到客户端。

这个没有测试过,不知道怎么做

 

方案三:

将调用页面window.showmodaldialog方法改为window.open方法,事情完美解决,我就是用的这种方法。

方案四:


掉用下载方法的时候,将下载方法放到iframe中:



<td width="15%" style="text-align: right; height: 52px;">
                        <label id='tdsqs'>
                            申请书:</label>
                    </td>
                    <td colspan="3">
                        <asp:Label ID="labSQS" runat="server"></asp:Label>
                       
                        <asp:Button ID="btnDownLoadSQS" runat="server" Text="下载" Style="color: #fff; text-align: center;
                            width: 53px; height: 26px; line-height: 26px; background: url(../images/search.gif) no-repeat;
                            display: none; margin-bottom: 0px;" ValidationGroup="download" OnClick="btnDownLoadSQS_Click" />
                        <a href="javascript:void(0)" οnclick="jj('btnDownLoadSQS')" style="color: Blue">下载</a>
                    </td>


 <iframe id="download" runat="server" style="display:none;"></iframe>


后台代码:

 protected void btnDownLoadSQS_Click(object sender, EventArgs e)
        {
            string fileName = labSQS.Text;//客户端保存的文件名
            string filePath = hidsqs.Value;
            downLoad(fileName, filePath);
        }



   public void downLoad(string fileName, string filePath)
        {
            try
            {
                filePath = Server.MapPath("../UploadFile/ExamFile/" + filePath);//路径               
                if (!File.Exists(filePath))
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "3", "<script>alert('下载文件时出现错误,可能是该文件已经被删除!')</script>");
                }
                else
                {
                    download.Attributes["src"] = "DownLoad.aspx?filePath=" + filePath + "&fileName=" + fileName; ;
                }
            }
            catch (Exception ex)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "fsdf", "<script>alert('下载文件时出现错误,可能是该文件已经被删除!')</script>");
            }
        }


链接的download页面:

后台代码:


 protected void Page_Load(object sender, EventArgs e)
        {
            string filePath = Request.QueryString["filePath"];
            string fileName = Request.QueryString["fileName"]; 
            //string filePath = Server.MapPath("\\PDF\\a.txt");
          
            if (File.Exists(filePath))
            {
                FileInfo file = new FileInfo(filePath);
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); //解决中文乱码 

                if (string.IsNullOrEmpty(fileName))
                {
                    fileName = file.Name;
                }

                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fileName)); //解决中文文件名乱码 
                // Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name); 
                Response.AddHeader("Content-length", file.Length.ToString());
                Response.ContentType = "appliction/octet-stream";
                Response.WriteFile(file.FullName);
                Response.End();
            }
        }


   





  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值