首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • 请问这个功能如何实现呢 [已结贴,结贴人:dnvvj]
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-17 17:36:02 楼主
    页面上一个输入信息的地方你输入一篇文章,点提交后,在文章内容保存到数据库后,同时把刚才输入的文字转成txt 然后弹出下载框  之后就能下载了。请问具体应该如何实现呢
    20  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-17 17:37:261楼 得分:0
    这问题好大……。

    还是等别人回答吧,我现在有点儿懒。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-17 17:38:342楼 得分:0
    转成txt后总得保存到一个地方吧?
    把这个地方的路径重定向打开,就可以了
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-17 17:42:503楼 得分:0
    写入数据库同时生成txt文件。页面内加个link并设置隐藏,文件生成后link加上txt的存放路径,并触发事件把link的地址打开。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-17 17:51:214楼 得分:0
    有没有简单一些的代码呢。有点难哦
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-17 22:54:425楼 得分:0
    default.aspx:

    HTML code
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server" Height="173px" TextMode="MultiLine" Width="304px"></asp:TextBox><br /> <br /> <asp:Button ID="Button1" runat="server" Text="得到TXT文件" PostBackUrl="~/txt.ashx" />&nbsp;</div> </form> </body> </html>


    default.aspx.cs:

    C# code
    using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }


    txt.ashx:

    C# code
    <%@ WebHandler Language="C#" Class="txt" %> using System; using System.Web; public class txt : IHttpHandler { public void ProcessRequest(HttpContext context) { string FullFileName = @"c:\1.txt"; System.IO.FileInfo DownloadFile = new System.IO.FileInfo(FullFileName); context.Response.Clear(); context.Response.ClearHeaders(); context.Response.Buffer = false; context.Response.ContentType = "application/octet-stream"; context.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8)); context.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString()); context.Response.WriteFile(DownloadFile.FullName); context.Response.Flush(); context.Response.End(); } public bool IsReusable { get { return false; } } }
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-18 10:45:276楼 得分:20
    我改写了一下:

    test.aspx:

    HTML code
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> </head> <body> <form id="form1" runat="server"> <div> 请输入文件名称: <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /> <br /> 请输入内容: <br /> <br /> <asp:TextBox ID="TextBox1" runat="server" Height="192px" TextMode="MultiLine" Width="252px"></asp:TextBox> <br /> <br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="生成下载文件" /></div> </form> </body> </html>


    test.aspx.cs:

    C# code
    using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class test : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, System.EventArgs e) { try { string str = TextBox1.Text.ToString().Trim(); byte[] buff = System.Text.Encoding.Unicode.GetBytes(str); //byte[] buff = System.Text.Encoding.UTF8.GetBytes(str); byte[] outBuff = new byte[buff.Length + 2]; // 使用文件流方式写入UniCode编码的doc文件。 byte[] mark = { 0xFF, 0xFE }; outBuff[0] = mark[0]; outBuff[1] = mark[1]; for (int i = 0; i < buff.Length; i++) { outBuff[i + 2] = buff[i]; } Context.Response.ContentType = "application/octet-stream"; string fileName = TextBox2.Text.ToString().Trim(); Context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8) + "\""); Context.Response.AddHeader("Content-Length", outBuff.Length.ToString()); Response.BufferOutput = true; Response.Clear(); Context.Response.BinaryWrite(outBuff); Context.Response.End(); } catch (Exception ex) { ex.ToString(); } finally { } } }
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • txgaozhao
    • 等级:
    发表于:2008-05-18 10:50:197楼 得分:0
    事物处理起来很复杂
    修改 删除 举报 引用 回复

    网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
    北京创新乐知广告有限公司 版权所有 京 ICP 证 070598 号
    世纪乐知(北京)网络技术有限公司 提供技术支持
    Copyright © 2000-2008, CSDN.NET, All Rights Reserved