I tried to save rendered C# web browser to my hdd. But it only save html source only, no css or jquery js file. I tried with 3 methods.
2.It only creates content text. No html, css, js File.WriteAllText(@"text.txt", webBrowser5.Document.Body.InnerText);
3.It creates bigger html file, still no css or jquery js files writer.Write(webBrowser5.DocumentText);
private void button1_Click(object sender, EventArgs e)
{
String source = ("viewsource.html");
StreamWriter writer = File.CreateText(source);
String myDocumentPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\111.html";
//It only creates only html file without any css, and jquery js files.
File.WriteAllText(myDocumentPath, webBrowser5.Document.Body.Parent.OuterHtml, Encoding.GetEncoding(webBrowser5.Document.Encoding));
//it only creates content text
File.WriteAllText(@"text.txt", webBrowser5.Document.Body.InnerText);
//It creates bigger html file, still no css or jquery js files
writer.Write(webBrowser5.DocumentText);
writer.Close();
}
I found solution on codeproject. MHTML is the way to go. http://www.codeproject.com/Articles/12977/Harvesting-Web-Content-into-MHTML-Archive
Other solution is save as image: http://www.codeproject.com/Articles/6601/Capture-an-HTML-document-as-an-image
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.