I used this code to open the HTML page in HTML editor in c#.
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
using (OpenFileDialog ofd = new OpenFileDialog() { Multiselect =
false, ValidateNames = true, Filter = "HTML|*.html" })
if (ofd.ShowDialog() == DialogResult.OK)
{
textBox1.Text = ofd.FileName;
FileStream fs = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read);
webBrowser1.DocumentStream = fs;
}
}
and also I used this code to save the changes
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();
}
}
However, the only line is saved in my HTML page is this message: System.Windows.Forms.WebBrowser. Do you have any idea that how can I save the content of the HTML page? Thanks
sw.WriteLine(webBrowser1)is implicitly callingwebBrowser1'sToString()method which gives you the content you're currently getting. You have to writewebBrowser1's documentStream.