Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在c中保存HTML编辑器的HTML内容#_C#_Html - Fatal编程技术网

C# 如何在c中保存HTML编辑器的HTML内容#

C# 如何在c中保存HTML编辑器的HTML内容#,c#,html,C#,Html,我使用此代码在c#中的HTML编辑器中打开HTML页面 我还使用了这段代码来保存更改 private void saveToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog svf = new SaveFileDialog(); svf.Filter = "Text Files (.html)|*.html"; if (svf.ShowDialog()

我使用此代码在c#中的HTML编辑器中打开HTML页面

我还使用了这段代码来保存更改

 private void saveToolStripMenuItem_Click(object sender, EventArgs e)
    {
        SaveFileDialog svf = new SaveFileDialog();
        svf.Filter = "Text Files (.html)|*.html";

        if (svf.ShowDialog() == DialogResult.OK)
        {
            System.IO.StreamWriter sw = new System.IO.StreamWriter(svf.FileName);

            sw.WriteLine(webBrowser1);
            sw.Close();
        }
    }
但是,我的HTML页面中保存的唯一一行是以下消息:System.Windows.Forms.WebBrowser。
你知道如何保存HTML页面的内容吗?谢谢

以下各项应能满足您的要求:

System.IO.StreamWriter sw=new System.IO.StreamWriter(svf.FileName);
webBrowser1.DocumentStream.CopyTo(西南基流);
sw.Flush();
sw.Close()

您无法工作的原因是您试图直接将对象写入流,正如前面所述,它隐式调用了ToString()方法。

这一行
sw.WriteLine(webBrowser1)
隐式调用了
webBrowser1
ToString()
方法,该方法为您提供当前获取的内容。您必须编写
webBrowser1
的documentStream.CopyTo(sw):对于括号内的“sw”,它给了我以下错误:Argument1:Conot从“system.IO.StreamWriter”转换为“system.IO.stream”
 private void saveToolStripMenuItem_Click(object sender, EventArgs e)
    {
        SaveFileDialog svf = new SaveFileDialog();
        svf.Filter = "Text Files (.html)|*.html";

        if (svf.ShowDialog() == DialogResult.OK)
        {
            System.IO.StreamWriter sw = new System.IO.StreamWriter(svf.FileName);

            sw.WriteLine(webBrowser1);
            sw.Close();
        }
    }