生成静态页html
代码:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks; namespace Framework.Common
{
public class StaticPage
{
/// <summary>
/// html模板地址
/// </summary>
public string TemplateUrl { get; set; }
/// <summary>
/// 生成html保存地址
/// </summary>
public string DestinationUrl { get; set; }
/// <summary>
/// 要替换的键值对
/// </summary>
public Hashtable KValues { get; set; } public StaticPage() { }
public StaticPage(string templateUrl, string destinationUrl, Hashtable kValues)
{
this.TemplateUrl = templateUrl;
this.DestinationUrl = destinationUrl;
this.KValues = kValues;
} public bool Save()
{
bool _isOk = false;
WebResponse response = WebRequest.Create(TemplateUrl).GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
{
string tempContent = reader.ReadToEnd();
foreach (string item in KValues.Keys)
{
tempContent = tempContent.Replace("{" + item.ToString() + "}", KValues[item].ToString());
}
using (StreamWriter write = new StreamWriter(DestinationUrl, false, System.Text.Encoding.UTF8))
{
write.Write(tempContent);
write.Flush();
write.Close();
_isOk = true;
}
}
return _isOk;
}
}
}
使用:
Models.OfficialStoryInfo item = OfficialStoryInfoBLL.GetEntity(id);
string tempUrl = HttpContext.Current.Server.MapPath("~/temp/officialstory.txt");
string destUrl = HttpContext.Current.Server.MapPath("~/html/OfficialStory/" + item.ID + ".html");
System.Collections.Hashtable ht = new System.Collections.Hashtable();
ht.Add("title", item.Name);
ht.Add("contents", item.Description);
bool isok = new Common.StaticPage() { DestinationUrl = destUrl, KValues = ht, TemplateUrl = tempUrl }.Save();
生成静态页html的更多相关文章
- ASP.NET MVC 解析模板生成静态页一(RazorEngine)
简述 Razor是ASP.NET MVC 3中新加入的技术,以作为ASPX引擎的一个新的替代项.在早期的MVC版本中默认使用的是ASPX模板引擎,Razor在语法上的确不错,用起来非常方便,简洁的语法 ...
- 基于PHP生成静态页的实现方法
t1.php 复制代码 代码如下: <?php// 方法一根据模版生成静态页面// replaceTemplateString函数用于替换模板中指定字符串function replaceTemp ...
- 生成静态页面的PHP类
生成静态页面的PHP类: 复制代码代码如下: <?php class html { var $dir; //dir for the htmls(without/) var $ ...
- mvc分页生成静态页,mvc生成静态页
http://blog.csdn.net/xxj_jing/article/details/7899125 分页生成静态页 http://www.cnblogs.com/luanyilin/archi ...
- C# 用模板生成静态页
最近在研究静态页输出的问题,找了一些资料.做了一个简单的模板模式的静态输出 模板代码: <html xmlns="http://www.w3.org/1999/xhtml"& ...
- NET MVC RazorEngine 解析模板生成静态页
ASP.NET MVC 解析模板生成静态页一(RazorEngine) 简述 Razor是ASP.NET MVC 3中新加入的技术,以作为ASPX引擎的一个新的替代项.在早期的MVC版本中默认使用的是 ...
- tp 生成静态页
$this->fetch()返回的是html 可以直接写入到HTML文件内生成静态页
- dedesmc 手机端生成静态页
dedesmc 手机端生成静态页 1.首先下载插件,下载地址:https://pan.baidu.com/s/1Nfx_KBYuxRkZ7VzoPxy28g 密码:83x7 2.进入 dedecms ...
- ThinkPHP生成静态页buildHtml方法
原来ThinkPHP自带了生成静态页的函数buildHtml,使用起来很方便!最新的手册里没写这个方法,向大家介绍一下. PHP 1 2 3 4 5 6 7 8 9 10 11 protect ...
- ASP.NET MVC 利用Razor引擎生成静态页
实现原理及步骤: 1.通过ViewEngines.Engines.FindView查找到对应的视图,如果是部分视图,则用:ViewEngines.Engines.FindPartialView: 2. ...
随机推荐
- AVL树Python实现
# coding=utf-8 # AVL树Python实现 def get_height(node): return node.height if node else -1 def tree_mini ...
- python 编写远程连接服务器脚本
import paramiko client = paramiko.SSHClient()client.set_missing_host_key_policy(paramiko.AutoAddPoli ...
- 1.Redis的应用场景
转自:http://www.runoob.com/redis/redis-tutorial.html Redis开创了一种新的数据存储思路,使用Redis,我们不用在面对功能单调的数据库时,把精力放在 ...
- Spring MVC 异常处理 - ExceptionHandler
通过HandlerExceptionResolver 处理程序异常,包括Handler映射, 数据绑定, 以及目标方法执行时的发生的异常 实现类如下 /** * 1. 在 @ExceptionHand ...
- cv::circle《转》
void circle(CV_IN_OUT Mat& img, Point center, int radius, const Scalar& color, int thickness ...
- UI5-文档-4.22-Expression Binding
有时预定义的SAPUI5类型不够灵活,您希望在视图中执行简单的计算或格式化——这正是表达式真正有用的地方.我们使用它们根据数据模型中的当前数字格式化价格. Preview The price is n ...
- .net数据库连接防注入参数查询 命令执行 读取 备份 导出导入转化XML格式
ADO.NET是一组类库,让我们通过程序的方式访问数据库.SYSTEM.DATA这个类提供了统一的接口访问Oracle MSSQL Access.像SYSTEM.IO类操作文件一样. **connec ...
- ibernate 配置数据库方言
在开发hibernate的程序时,需要进行SessionFactory的配置,简单地说,也就是建立与数据库之间连接的配置,在hibernate中一般使用xml文件来进行配置,但是在该文件的 ...
- 第一个struct2程序(2)
第三步 需要使用ActionForm了.在Struts1.x中,必须要单独建立一个ActionForm类(或是定义一个动作Form),而在Struts2中ActionForm和Action已经二合一了 ...
- Lock()与RLock()锁
资源总是有限的,程序运行如果对同一个对象进行操作,则有可能造成资源的争用,甚至导致死锁 也可能导致读写混乱 锁提供如下方法: 1.Lock.acquire([blocking]) 2.Lock.rel ...