将网上的内容,读取到指定文件中【页面静态化】

出错:

已经将指定页面的内容读取到了test.html文件中,但是页面中有很多的乱码。

 

以下是一个简单的,将aspx文件生成静态html文件的代码

protected void Button1_Click(object sender, EventArgs e)
        {
            System.IO.StringWriter sw = new StringWriter();
            Server.Execute("index.aspx", sw);
            string contentStr = sw.ToString();
            string filePath = Server.MapPath("/");
            filePath += "test.html";
            StreamWriter stw = new StreamWriter(filePath, false, System.Text.Encoding.Default);
            stw.Write(contentStr);
            stw.Flush();
            stw.Close();
        }

 文件结构如下所示:

 

 

posted @ 2018-06-12 14:18  冬月二四  阅读(114)  评论(0编辑  收藏  举报