为了账号安全,请及时绑定邮箱和手机立即绑定

将 ac# 字符串保存为 html 文件

将 ac# 字符串保存为 html 文件

当年话下 2023-09-04 15:39:36
我有一个 c# 脚本,它在某个时候创建一个字符串变量,如何将其另存为 HTML 文件在脚本的同一目录中? string saveHtml = "<html>" +    "<head>" +    "  <title>Select Image</title>" +    "  <script type=\"text/javascript\">" +    "  function displayImage(elem) {" +    "    var image = document.getElementById(\"canvas\");" +    "    image.src = elem.value;        " +    "  }" +    "  </script>" +    "</head>" +    "<body>" +    "  <form name=\"controls\">" +    "    <img id=\"canvas\" src=\"pictures/fire1.jpg\" />" +    "    <select name=\"imageList\" onchange=\"displayImage(this);\">" +    "      <option value=\"pictures/001JRPchargeable.png\">Fire 1</option>" +    "      <option value=\"pictures/001JRPNonchargeable.png\">Fire 2</option>" +"</select>" +"  </form>" +"</body>" +"</html>";
查看完整描述

2 回答

?
慕桂英4014372

TA贡献1871条经验 获得超13个赞

class Program

{

    static void Main(string[] args)

    {

        string saveHtml = "<html>" +

                          "<head>" +

                          "  <title>Select Image</title>" +

                          "  <script type=\"text/javascript\">" +

                          "  function displayImage(elem) {" +

                          "    var image = document.getElementById(\"canvas\");" +

                          "    image.src = elem.value;        " +

                          "  }" +

                          "  </script>" +

                          "</head>" +

                          "<body>" +

                          "  <form name=\"controls\">" +

                          "    <img id=\"canvas\" src=\"pictures/fire1.jpg\" />" +

                          "    <select name=\"imageList\" onchange=\"displayImage(this);\">" +

                          "      <option value=\"pictures/001JRPchargeable.png\">Fire 1</option>" +

                          "      <option value=\"pictures/001JRPNonchargeable.png\">Fire 2</option>" +

                          "</select>" +

                          "  </form>" +

                          "</body>" +

                          "</html>";


        File.WriteAllText(@"C:\temp\theFile.html", saveHtml);

    }

}


查看完整回答
反对 回复 2023-09-04
?
慕后森

TA贡献1802条经验 获得超5个赞

您可以使用此代码:


string saveHtml = "<html>" +

    "<head>" +

    "  <title>Select Image</title>" +

    "  <script type=\"text/javascript\">" +

    "  function displayImage(elem) {" +

    "    var image = document.getElementById(\"canvas\");" +

    "    image.src = elem.value;        " +

    "  }" +

    "  </script>" +

    "</head>" +

    "<body>" +

    "  <form name=\"controls\">" +

    "    <img id=\"canvas\" src=\"pictures/fire1.jpg\" />" +

    "    <select name=\"imageList\" onchange=\"displayImage(this);\">" +

    "      <option value=\"pictures/001JRPchargeable.png\">Fire 1</option>" +

    "      <option value=\"pictures/001JRPNonchargeable.png\">Fire 2</option>" +

"</select>" +

"  </form>" +

"</body>" +

"</html>";



string path = @"D:\Test.html";

System.IO.File.WriteAllText(path, saveHtml)


查看完整回答
反对 回复 2023-09-04
  • 2 回答
  • 0 关注
  • 117 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信