【问题标题】:Write variables into an html file将变量写入 html 文件
【发布时间】:2012-03-17 04:45:55
【问题描述】:

有一个 .net 站点,我正在尝试在完成后将表单的 html 副本保存到服务器。问题是我如何让它将数据保存到 html 文档中,而不必再次编写整个内容。当我意识到这一点时,我走到了这一步。

        string activeDir = @"c:\Code";
        DateTime time = DateTime.Now;              
        string folformat = "MMdyy";
        string filformat = "hmsMMdyy";
        string fdate = time.ToString(folformat);
        string newPath = System.IO.Path.Combine(activeDir, fdate);
        System.IO.Directory.CreateDirectory(newPath);
        string newFileName = time.ToString(filformat)+".html";
        newPath = System.IO.Path.Combine(newPath, newFileName);
        if (!System.IO.File.Exists(newPath))
        {
            TextWriter tw = new StreamWriter(newPath);
            tw.WriteLine(700linesofhtml);
        }

有没有更好的方法?

【问题讨论】:

    标签: c# asp.net html forms


    【解决方案1】:

    我不确定,问题是什么,而不是你是否可以使用

    File.AppendAllText(string path, string content)
    

    http://msdn.microsoft.com/en-us/library/ms143356.aspx

    【讨论】:

    • 我有一个带有文本框 A、B 和 C 的 html 表单。如何将具有 A、B 和 C 值的表单写入新的 html 文件而无需重写整个代码.
    • 您需要将回发表单数据转换为“人类可读”字符串(html 文件)吗?
    • 是的,这正是我想要做的。
    • 尝试从 Request.Form 集合中读取表单数据,这样您就可以将其格式化为一些 StringBuilder 并输出到文件。
    猜你喜欢
    • 2011-06-19
    • 1970-01-01
    • 2020-11-04
    • 2015-06-06
    • 2013-10-03
    • 2015-05-11
    • 1970-01-01
    • 2018-01-01
    • 1970-01-01
    相关资源
    最近更新 更多