asp.net动态生成txt文本文件供用户下载

 一,JS动态创建表单

 var result = "   <form method='post'  action='../xiazai.aspx'><table width='100%' border='0' cellpadding='0' cellspacing='1' bgcolor='#BDB4A2'>"+
                "<tr>"+
                  "<td width='40' height='40' bgcolor='#CCC0AA'>&nbsp;</td>"+
                  "<td colspan='3' align='center' bgcolor='#F3EDDD' class='font_14'>共生成"+arrCon[1]+"注选号,共计"+(Number(arrCon[1])*2)+"元。</td>"+
                  "<td width='40' bgcolor='#CCC0AA'>&nbsp;</td>"+
                "</tr>";
             result += "<tr><td height='40' bgcolor='#CCC0AA'>&nbsp;</td>";
             var content = arrCon[0];
             var array = content.split(";");
             for(var i=0;i<array.length;i++){
              result += " <td align='center'  bgcolor='#FEFBF4'><span class='ft166C5'> <input name='txt1' type='hidden' value='"+array[i]+"/t/n' />  "+array[i]+" </span></td>"
              if((i+1)%3 == 0){
               result += "<td bgcolor='#CCC0AA'></td></tr><tr><td height='40' bgcolor='#CCC0AA'>&nbsp;</td>"
              }
             }    
              result+= "</tr></table>  <input id='Submit1' type='submit'  value='保存到本地'/></form>";

 

二  aspx.cs代码实现动态打印

     
    protected void Page_Load(object sender, EventArgs e)
    {
       // ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + Request.Form["txt1"] + "')</script>");
        string FileName = "彩讯网----彩票缩水";
        Response.ContentType = "Application/octet-stream";
        Response.AppendHeader("Content-Disposition", "attachment;filename=/"" + System.Web.HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8) + ".txt/"");
        HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
        Response.Write(Request.Form["txt1"]);
        Response.Flush();
        Response.End();
        ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('文件下载成功')</script>");
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值