c# 将日志文件显示在WebBrowser控件中

来源:互联网 发布:淘宝退款怎么申请介入 编辑:程序博客网 时间:2024/05/18 10:49
//由于日志中含有中文,用常用的Navigate()方法会含有乱码,所以用这种流的方式,一行一行的读。                string fullPath = @"F:\comback\Release\log\20121216.Log";                StringBuilder sb = new StringBuilder("");                StreamReader streamReader = null;                try                {                    streamReader = new StreamReader(fullPath, Encoding.UTF8);                        string line = streamReader.ReadLine();                    while (!string.IsNullOrEmpty(line))                    {                        sb.Append(line + "<br>");                        line = streamReader.ReadLine();                    }                    this.webBrowser1.DocumentText = sb.ToString();                }                catch (Exception ee)                {                    MessageBox.Show("" + ee.Message);                }                finally                {                    if (streamReader != null)                    {                        streamReader.Close();                    }                }