生成静态页面方法 .NET
原文发布时间为:2009-09-30 —— 来源于本人的百度文章 [由搬家工具导入]
采用模板法:【例子中的两个页面以及生成的页面均在同一个目录,自己可以去改】
模板Template.htm:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>标题:$htmlformat[0]</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<div style="text-align: center;">
内容
</div>
<div style="text-align: center; font-size: 16px; font-weight: bold;$htmlformat[1]">$htmlformat[2]
</div>
</body>
</html>
后台程序:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
public partial class ChangeToHtml : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
ToHTML();
}
protected void ToHTML()
{
string[] format = new string[3];//定义和htmlformat标记数目一致的数组
StringBuilder htmltext = new StringBuilder();
try
{
using (StreamReader sr = new StreamReader(Server.MapPath("Template.htm"), Encoding.GetEncoding("GB2312")))
{
String line;
while ((line = sr.ReadLine()) != null)
{
htmltext.Append(line);
}
sr.Close();
}
}
catch
{
Response.Write("<script>alert('读取文件错误')</script>");
}
//--------给标记数组赋值-----------//
format[0] = "静态页面生成";
format[1] = "color:red";
format[2] = "生成了静态HTML";
//-------替换html里的标记为你想加的内容-----------//
for (int i = 0; i < 3; i++)
{
htmltext.Replace("$htmlformat[" + i + "]", format[i]);
}
//----------生成html文件------------//
try
{
using (StreamWriter sw = new StreamWriter(Server.MapPath(DateTime.Now.ToString("yyyyMMddHHmmss") + ".htm"), false, Encoding.GetEncoding("GB2312")))
{
sw.WriteLine(htmltext);
sw.Flush();
sw.Close();
}
}
catch
{
Response.Write("<script>alert('文件生成失败')</script>");
}
}
}
生成静态页面方法 .NET的更多相关文章
- 三种C#.net生成静态页面的方法
ASP.NET生成静态页面方法主要有三种 第一种方法:向服务器的动态页面发送请求,获取页面的html代码.这种方法缺点显而易见:速度慢.另外如果请求的动态页面有验证控件的话,返回的html页面却无 ...
- PHP生成静态页面的方法
在PHP网站开发中为了网站推广和SEO等需要,需要对网站进行全站或局部静态化处理,PHP生成静态HTML页面有多种方法,比如利用PHP模板.缓存 等实现页面静态化,今天就以PHP实例教程形 ...
- 浅谈php生成静态页面
一.引 言 在速度上,静态页面要比动态页面的比方php快很多,这是毫无疑问的,但是由于静态页面的灵活性较差,如果不借助数据库或其他的设备保存相关信息的话,整体的管理上比较繁琐,比方修改编辑.比方阅读权 ...
- .net 生成 静态页面
.net 生成 静态页面 <!--Main.Aspx--> <%@ page language="C#" %> <%@ import namespac ...
- C#根据网址生成静态页面
HoverTree开源项目中HoverTreeWeb.HVTPanel的Index.aspx文件 是后台管理的首页. 包含生成留言板首页,以及显示用户名,退出等功能. 根据网址生成页面的方法: boo ...
- 比较详细PHP生成静态页面教程
一,PHP脚本与动态页面. PHP脚本是一种服务器端脚本程序,可通过嵌入等方法与HTML文件混合, 也可以类,函数封装等形式,以模板的方式对用户请求进行处理.无论以何种方式,它的基本原理是这样的.由客 ...
- [转]把动态页面.aspx 生成静态页面.html
本文转自:http://blog.csdn.net/csb5201314/article/details/5391688 如果要把主页Index.aspx 生成静态页面 Index.html后输出会提 ...
- PHP代码为什么不能直接保存HTML文件——>PHP生成静态页面教程
1.server会依据文件的后缀名去进行解析,假设是HTML文件则server不会进行语法解析.而是直接输出到浏览器. 2.假设一个页面中所有都是HTML代码而没有须要解析的PHP语法,则没有必要保存 ...
- PHP生成静态页面详解
PHP生成静态页面详解 看到很多朋友在各个地方发帖问PHP生成静态文章系统的方法,以前曾做过这样一个系统,遂谈些看法,以供各位参考.好了,我们先回顾一些基本的概念. 一,PHP脚本与动态页面. PHP ...
随机推荐
- JS - 箭头函数与 () {} 的作用域
foo () { // ... } 等价于 foo: function () { // ... } foo: () => { // ... } 范例: // 全局 name = 'zhangsa ...
- VPS搭建***
yum -y install epel-release** yum update yum -y install python-setuptools m2crypto supervisor easy_i ...
- ATMstart
import os, sys BASE_DIR = os.path.dirname(__file__)sys.path.append(BASE_DIR) from core import src if ...
- 【mysql】 数据库字符集和排序规则
库的字符集影响表和字段的字符集 数据库字符集 >表的字符集 > 字段的字符集 (从前往后优先级由低到高,从左往右继承,如果表没设置字符集,继承数据库的,如果字段没设置,继承表的) 数据库的 ...
- python编写登录接口
要求: 输入用户名密码 认证成功显示欢迎信息 输错三次以后锁定 代码如下: # Author:YKwhile(True): select=input('请问是注册还是登录') if selec ...
- kubernetes dashboard permission errors
kubernetes dashboard 的权限错误 warning configmaps is forbidden: User "system:serviceaccount:kube-sy ...
- python语言介绍
Python诞生于1989年,作者是吉多.范罗苏姆,人称龟叔,由C语言实现的. 1999年,基于python的web框架Zope 1诞生,标志着python向web领域迈出了第一步,现在这个框架好像不 ...
- Poj3061Subsequence
A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, a ...
- Proguard returned with error code 1. See console
满世界的bug. 微信支付,Windows的远程桌面. Android的 , Proguard returned with error code 1. See console解决办法" 真的 ...
- 洛谷P1553数字反转升级版
题目链接:https://www.luogu.org/problemnew/show/P1553