C#對html的操作-創(chuàng)新互聯(lián)

1,獲取相對路徑的html然后保存到本地路徑C#對html的操作
/// <summary> /// Html方法 /// </summary> /// <returns></returns> public void CollectionContent(string url) { Response.ContentType = "html/plain"; Response.Charset = "gb2312"; Response.ContentType = "html/html"; Response.Charset = "utf-8"; string htmlContent = clsCommonEx.GetPageHtml(url); try { StreamWriter sw = null; Encoding code = Encoding.GetEncoding("gb2312"); string path = HttpContext.Current.Server.MapPath("/cache/"); string htmlfilename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html";// 寫文件 try { sw = new StreamWriter(path + htmlfilename, false, code); sw.Write(htmlContent); sw.Flush(); } catch (Exception ex) { HttpContext.Current.Response.Write(ex.Message); HttpContext.Current.Response.End(); } finally { sw.Close(); } } catch { Response.Write("The file could not be wirte:"); } }

2,生成html

永年網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),永年網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為永年1000多家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)要多少錢,請找那個售后服務(wù)好的永年做網(wǎng)站的公司定做! //生成HTML頁 public static bool WriteFile(string strText, string strContent, string strAuthor) { string path = HttpContext.Current.Server.MapPath("/news/"); Encoding code = Encoding.GetEncoding("gb2312"); // 讀取模板文件 string temp = HttpContext.Current.Server.MapPath("/news/text.html"); StreamReader sr = null; StreamWriter sw = null; string str = ""; try { sr = new StreamReader(temp, code); str = sr.ReadToEnd(); // 讀取文件 } catch (Exception exp) { HttpContext.Current.Response.Write(exp.Message); HttpContext.Current.Response.End(); sr.Close(); } string htmlfilename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html"; // 替換內(nèi)容 // 這時,模板文件已經(jīng)讀入到名稱為str的變量中了 str = str.Replace("ShowArticle", strText); //模板頁中的ShowArticle str = str.Replace("biaoti", strText); str = str.Replace("content", strContent); str = str.Replace("author", strAuthor); // 寫文件 try { sw = new StreamWriter(path + htmlfilename, false, code); sw.Write(str); sw.Flush(); } catch (Exception ex) { HttpContext.Current.Response.Write(ex.Message); HttpContext.Current.Response.End(); } finally { sw.Close(); } return true; }

文章標(biāo)題:C#對html的操作-創(chuàng)新互聯(lián)
標(biāo)題來源:http://muchs.cn/article14/dsioge.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈域名注冊、定制開發(fā)、商城網(wǎng)站網(wǎng)站營銷、動態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)