网站静态化
using System.IO;
using System.Windows.Forms;
using System.Text;
using System.Net;
//静态化
protected string jingtaihua(string url, int i){
//创建文件
string dt = DateTime.Now.ToLongDateString();
string activeDir = @"c:\" + dt;
System.IO.Directory.CreateDirectory(activeDir);
string file = activeDir + "\\" + i + "kkk.htm";
string path =string.Format("http://localhost:10444/linshizhuaqu/"+url);
byte[] b = new byte[39824];
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(path);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream streamReceive = response.GetResponseStream();
Encoding encoding = Encoding.GetEncoding("GB2312");
StreamReader streamReader = new StreamReader(streamReceive, encoding);
string strResult = streamReader.ReadToEnd();
streamReader.Close();
//写入文件
if (File.Exists(file))
{
File.Delete(file);
StreamWriter sw = File.AppendText(file);
sw.WriteLine(strResult);
sw.Flush();
sw.Close(); //关闭流
sw.Dispose(); //销假对象
}
else
{
StreamWriter sw = File.CreateText(file);
sw.WriteLine(strResult);
sw.Flush();
sw.Close();
sw.Dispose();
}
return file;
}