c# webBrowser 控件里的内容保存到本地。 保存文件拓展名XML
展开全部
给个思路吧,webBrowser1.DocumentStream获得文档流,然后把文档流复制到文件流中保存。
更多追问追答
追问
能给段代码吗?
追答
Stream stream = webBrowser1.DocumentStream;
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
using(FileStream fileStream = new FileStream("test.xml", FileMode.Create, FileAccess.ReadWrite))
{
fileStream.Write(buffer, 0, buffer.Length);
fileStream.Flush();
}
stream.Close();
// 建议使用 StreamReader 和 StreamWriter 包装一下流。
// 没有考虑多线程、异常什么的,这些代码你要自己加。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompletedSavePic);
webBrowser.Navigate(url);
private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser webBrowser1 = (WebBrowser)sender;
Stream stream = webBrowser1.DocumentStream;
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
using(FileStream fileStream = new FileStream("test.xml", FileMode.Create, FileAccess.ReadWrite))
{
fileStream.Write(buffer, 0, buffer.Length);
fileStream.Flush();
}
stream.Close();
}
webBrowser.Navigate(url);
private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser webBrowser1 = (WebBrowser)sender;
Stream stream = webBrowser1.DocumentStream;
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
using(FileStream fileStream = new FileStream("test.xml", FileMode.Create, FileAccess.ReadWrite))
{
fileStream.Write(buffer, 0, buffer.Length);
fileStream.Flush();
}
stream.Close();
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询