Recently, I am working on some static pages for a website to directly generate static pages for some dynamic pages.
We have long known that this can be implemented using WebClient, which can be used to remotely read dynamic pages.
Then write the read content to the corresponding static file. To put it bluntly, there are two actions: read and write.
However, during reading and writing, you must ensure that the encoding is consistent. Otherwise, the content may be garbled or the webpage may be garbled.
I also read the solution for solving static pages on the Internet.
Today, I will share my simplest method with you. Maybe the experts think this is too simple, too common, and there is no need to send it.
However, the content I wrote is relatively simple and cannot be written in depth, so I wrote it to my friends who have such troubles.
Friends who can generate a common solution or have a simpler solution remember to reply to the message.
Code
1 private void makehtml (string URL, string SaveFile)
2 {
3 WebClient WC = new WebClient ();
4 byte [] BS = WC. downloaddata (URL );
5 string html = encoding. getencoding ("gb2312"). getstring (BS );
6 string SaveFile = server. mappath (SaveFile );
7 streamwriter Sw = new streamwriter (SaveFile, false, encoding. getencoding ("gb2312 "));
8 SW. Write (HTML );
9 Sw. Close ();
10}