日期:2014-05-17 浏览次数:20452 次
protected void btn1_onclick(object sender,EventArgs e) { AddFilesByHtml("index.html", "http://192.168.1.11/index.aspx"); } /// <summary> /// 静态页 /// </summary> /// <param name="fileName">要保存的文件名</param> /// /// <param name="url">动态页路径url</param> /// <returns></returns> public static string AddFilesByHtml(string fileName, string url) { System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url); System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse(); System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")); string innerHtml = reader.ReadToEnd(); if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath(fileName))) { System.IO.File.Delete(System.Web.HttpContext.Current.Server.MapPath(fileName)); } System.Threading.Thread.Sleep(100); StreamWriter SW = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath(fileName), false, Encoding.GetEncoding("utf-8")); SW.WriteLine(innerHtml); SW.Close(); return fileName; }