| 網(wǎng)頁靜態(tài)化,生成靜態(tài)文件的類 using System; using System.IO; using System.Net; using System.Web; namespace ClassLibrary.DataClass { /// <summary> /// GenHtml 的摘要說明。 /// </summary> public class GenHtml {      public static    string path="";      public static    string fileName="";      public static    string transUrl="";     public GenHtml()     {      //      // TODO: 在此處添加構(gòu)造函數(shù)邏輯      //     }     /// <summary>     /// 轉(zhuǎn)換成靜態(tài)文件     /// </summary>     /// <param name="path">要寫入靜態(tài)文件的真實(shí)路徑</param>     /// <param name="fileName">真實(shí)的文件名</param>     /// <param name="transUrl">要轉(zhuǎn)換的地址</param>     public static bool writeFile(string path, string fileName, string transUrl)     {      //是否正確生成      bool bSuccess = false;      StreamReader sr;      StreamWriter sw;      try       {       WebRequest HttpWebRequest = WebRequest.Create(transUrl);       WebResponse HttpWebResponse = HttpWebRequest.GetResponse();       sr = new StreamReader(HttpWebResponse.GetResponseStream());       string strHtml = sr.ReadToEnd();       sr.Close();            if(!System.IO.Directory.Exists(path))       {       System.IO.Directory.CreateDirectory(path);       }       string PathAndName = path + fileName;       if (System.IO.File.Exists(PathAndName))       {        System.IO.File.Delete(PathAndName);       }       sw = File.CreateText(PathAndName);       sw.WriteLine(strHtml);       sw.Close();       //生成成功       bSuccess = true;      }      catch      {      }      return bSuccess;     }     public void    threadWriteFile()     {      StreamReader sr;      StreamWriter sw;      try       {       WebRequest HttpWebRequest = WebRequest.Create(transUrl);       WebResponse HttpWebResponse = HttpWebRequest.GetResponse();       sr = new StreamReader(HttpWebResponse.GetResponseStream());       string strHtml = sr.ReadToEnd();       sr.Close();            if(!System.IO.Directory.Exists(path))       {        System.IO.Directory.CreateDirectory(path);       }       string PathAndName = path + fileName;       if (System.IO.File.Exists(PathAndName))       {        System.IO.File.Delete(PathAndName);       }       sw = File.CreateText(PathAndName);       sw.WriteLine(strHtml);       sw.Close();      }      catch      {      }     }     /// <summary>     /// 刪除生成文件     /// </summary>     /// <param name="path">文件真實(shí)路徑</param>     /// <param name="fileName">文件名</param>     /// <returns>布爾值</returns>     public static bool delFile(string path,string fileName)     {      //是否成功的標(biāo)志      bool bSuccess=false;      try      {       string pathAndName=path+fileName;       if(System.IO.File.Exists(pathAndName))       {        System.IO.File.Delete(pathAndName);        bSuccess=true;       }      }      catch      {      }     return bSuccess;     } } } | 
|  |