#region 生成静态页
/// <summary>
/// 生成静态页
/// </summary>
/// <param name="URL">要生成的页面</param>
/// <param name="savePath">保存位置</param>
/// <param name="htmlName">页面名称</param>
/// <returns></returns>
public string Buiding(string URL, string savePath, string htmlName)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);//向url所在的服务器发送一个请求
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //获得服务器的回应
string charset = response.CharacterSet;
Encoding encode = Encoding.GetEncoding(charset);
TextReader text = new StreamReader(response.GetResponseStream(), encode);//初始化流
string htmlContent = text.ReadToEnd();//获得网页内容
response.Close();
string path = savePath + htmlName + ".html";
FileInfo t = new FileInfo(Server.MapPath(path));//将网页内容保存到html文件
StreamWriter html = t.CreateText();
html.WriteLine(htmlContent);
html.Close();
return path;
}
catch (Exception)
{
throw;
}
} /// <summary>
/// 根据模版生成静态页
/// </summary>
/// <returns></returns>
public string BuidingByModel()
{
try
{
Encoding encode = Encoding.GetEncoding("utf-8");//设置编码方式
TextReader tr = new StreamReader(Server.MapPath("~/Model.html"), encode);//读取模版页初始化流
string htmlContent = tr.ReadToEnd();//获得网页内容
htmlContent = htmlContent.Replace("$NowTime$", "替换文本");
tr.Close();
string path = "~/" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".html";
FileInfo t = new FileInfo(Server.MapPath(path));//将网页内容保存到html文件
StreamWriter html = t.CreateText();
html.WriteLine(htmlContent);
html.Close();
return path;
}
catch (Exception)
{ throw;
}
}
#endregion 生成静态页

C#_生成HTML的更多相关文章

  1. X.509证书_生成X.509协议的证书

    用法:1. 用NOTE打开,修改按实际情况脚本中的(1)~ (6)处参数2. 找一台含JVM环境的WIN机器3. 双击执行后,会生成一对密钥4. 请确保当前使用的JDK版本为6.0!!! @echo ...

  2. FPGA工程中用C语言对文件进行处理_生成mif文件

    本博客中有用verilog处理文件数据的代码,本博文采用C 处理文件中的数据. 有时候要生成一个mif文件—— altera memory  initial file.本次工程中我得到的是一个大型的数 ...

  3. python之单元测试_生成测试报告

    (1)HTMLTestRunner.py的下载路径:https://pan.baidu.com/s/1Yk2E8d8bIo5_rmpussOE9Q 提取码:0jae (2)HTMLTestRunner ...

  4. Oracle Awr报告_生成

    AWR的概念 Oracle数据库是一个使用量很多的数据库,关于Oracle数据库的性能.Oracle10g以后,Oracle提供了一个性能检测的工具:AWR(Automatic Workload Re ...

  5. 阶段1 语言基础+高级_1-3-Java语言高级_1-常用API_1_第3节 Random类_10-练习一_生成1-n之间

    生成随即数的时候,总是会短一个,因为它是从0开始的 这是左闭右闭区间. 循环100次输出的结果

  6. 建字段_添加数据_生成json.php

    <?php header("Content-Type:text/html;charset=utf8"); class db{ static $localhost = &quo ...

  7. Vivado完成综合_实现_生成比特流后发出提醒声音-原创☺

    之前做技术支持时,有过客户吐槽Vivado运行时间长,又不能在完成工作后发送提醒,这两天又有人提起,所以决定写篇帖子. 大家知道,Vivado的技术文档总提及tcl,不过似乎很不招人待见,很少有人研究 ...

  8. Python学习笔记_生成验证码

    import random def verification_code(): num = [str(x) for x in range(10)] # 列表生成器0-9 upper = [chr(x) ...

  9. Oracle——生成Awr报告

    Oracle--生成Awr报告 AWR的概念 Oracle数据库是一个使用量很多的数据库,关于Oracle数据库的性能.Oracle10g以后,Oracle提供了一个性能检测的工具:AWR(Autom ...

随机推荐

  1. php重修

    阅读顺序: http://www.laruence.com/2008/08/11/147.html  深入浅出php http://www.laruence.com/2008/06/18/221.ht ...

  2. 2016"百度之星" - 初赛(Astar Round2A)Gym Class(拓扑排序)

    Gym Class  Accepts: 849  Submissions: 4247  Time Limit: 6000/1000 MS (Java/Others)  Memory Limit: 65 ...

  3. golang time and duration

    package mainimport "fmt"import "time"func main() { p := fmt.Println // We'll sta ...

  4. JavaScript - Html 中使用JavaScript

    把JavaScript插入到HTML页面要使用<script>元素.使用这个元素可以把JavaScript嵌入到HTML页面中,让脚本与标记混合在一起:也可以包含外部的JavaScript ...

  5. wp8 入门到精通 测量代码执行时间

    Stopwatch time = new Stopwatch(); byte[] target = new byte[size]; for (int j = 0; j < size; j++) ...

  6. 关于Application Insights遥测功能使用【遇到问题】

    简介:Application Insights是微软发布的一个在线服务,可以监测自己的网站应用,进行性能管理以及使用分析. Application Insights功能一开始是出现在Visualstu ...

  7. ML 06、感知机

    机器学习算法 原理.实现与实践  —— 感知机 感知机(perceptron)是二分类的线性分类模型,输入为特征向量,输出为实例的类别,取值+1和-1.感知机学习旨在求出将训练数据进行线性划分的分离超 ...

  8. MapKit 添加大头针

    #import "ViewController.h" #import <MapKit/MapKit.h> #import "MYAnnotation.h&qu ...

  9. ios编码转换 国标 UTF-8

    我们知道,使用NSURLConnection的代理方法下载网页,存到一个NSData中, NSMutableData *pageData; [pageData appendData:data]; 如果 ...

  10. 遍历windows驱动

    驱动都存在 \\Driver 或者 \\FileSystem 目录对象里 我们只需要遍历这两个目录就可以遍历windows所有驱动 知识点 \\Driver  \\FileSystem (dt _OB ...