.net 根据模板创建html文件

模板文件:

<!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>模板</title>
</head>
<body>
    $content$
</body>
</html>

代码如下:

        /// <summary>
        /// 创建html文件
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public string UpHtmlFile(string content)
        {
            string TemplateFile = Server.MapPath("../../../Public/WorkPlan/Template.html");
            string newfilename = Guid.NewGuid().ToString() + ".html";
            string path = Server.MapPath(string.Format("../../../Public/WorkPlan/{0}/", DateTime.Now.ToString("yyyy-MM-dd")));
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            string NewFile = path + newfilename;
            File.Copy(TemplateFile, NewFile, true);
            FileStream myfile = new FileStream(NewFile, FileMode.Open);
            StreamReader myStreamReader = new StreamReader(myfile, Encoding.UTF8);
            string strhtml = myStreamReader.ReadToEnd();
            string stroutput = strhtml.Replace(" $content$", content);
            myStreamReader.Close();
            myfile = new FileStream(NewFile, FileMode.OpenOrCreate);
            StreamWriter sw = new StreamWriter(myfile, Encoding.UTF8);
            sw.Write(stroutput);
            sw.Close();
            return newfilename;
        }
时间: 2024-08-30 12:32:52

.net 根据模板创建html文件的相关文章

Java根据html模板创建 html文件

1.创建html的java代码 package com.tydic.eshop.util; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Calendar; /** * @ClassName: CreateHtmlUtils * @Description: Java 根据模板创建 html * @author * @date 2016年4月22日 下午3:51:16 */ pub

上传列表模板,并使用列表模板创建列表

1.上载列表模板 网站设置---Web设计器库---列表模板---文件---上载文档(选择*.stp文件上传) 2.利用列表模板创建列表 网站内容---添加应用程序---选择你的列表模板---创建 http://www.2cto.com/os/201406/308004.html

itextsharp利用模板生成pdf文件笔记

iTextSharp是一款开源的PDF操作类库,使用它可以快速的创建PDF文件. 中文参考网站:http://hardrock.cnblogs.com/ http://pdfhome.hope.com.cn/Article.aspx?CID=bf51a5b6-78a5-4fa3-9310-16e04aee8c78&AID=f5fe52dd-8419-4baa-ab1c-ea3f26952132 英文参考网站:http://itext.ugent.be/library/ ·  技术文章(http:

使用word的xml模板生成.doc文件

一.编辑模板 替换地方以变量标记如"案件编号"可写成{caseNo} template.xml 二.准备数据 以HashMap封装数据,原理是替换模板中的变量 三.替换操作 选择输出位置:writePath WordUtil.printWordbyXMLWithOutputPath(templateFile, writePath, filename, dataMap); /** * 打印word文档(传入参数需要传入输出文件的保存路径的) * @param templateFile *

03_Weblogic之配置简单域:启动和配置域,使用模板创建域,使用控制台

 1  域:概览 是Oracle Weblogic Server的基本管理单元 始终包含一个配置为管理服务器的Oracle WebLogic Server实例 域中可以包括一些称为受管服务器的Oracle Weblogic Server实例(可选) 还可以包含协同工作的服务器实例的集群. 2. 域图 3.配置域 一  安装后,配置将在其上开发和部署应用程序的域. 二  通过创建域,您可以定义资源集合,例如: -----受管服务器 -----集群 -----数据库连接 -----安全服务 --

docker通过模板创建镜像以及容器、仓库和数据管理

笔记内容:docker通过模板创建镜像以及容器.仓库和数据管理笔记日期:2018-02-05 25.5 通过模板创建镜像 25.6 容器管理 25.7 仓库管理 25.8 数据管理 25.5 通过模板创建镜像 1.既然是通过模板创建镜像,那么首先肯定得先下载一个模板,地址如下: http://openvz.org/Download/templates/precreated 打开以上网址选择一个模板进行下载,我这里下载的是centos-6-x86-minimal.tar.gz (signature

Docker中通过模板创建镜像,Docker容器、仓库及数据管理

1.通过模板创建镜像 (1)首先去下载一个模板 http://openvz.org/Download/templates/precreated //下载速度不快,阿铭下载了一个centos6的模板centos-6-x86-minimal.tar.gz (2)导入该镜像的命令为: cat centos-6-x86-minimal.tar.gz|docker import - centos6 (3)查看导入的镜像 docker images (4)导出镜像: 把现有镜像,导出为一个文件: docke

如何在桌面上创建程序文件夹让每个登录用户都能访问呢?

如何在桌面上创建程序文件夹让每个登录用户都能访问呢? ?Lander Zhang 专注外企按需IT基础架构运维服务,IT Helpdesk 实战培训践行者博客:https://blog.51cto.com/lander IT Helpdesk 工程师实战培训课程:https://edu.51cto.com/lecturer/733218.html轻松进外企:IT Helpdesk工程师实战自学之路:https://blog.51cto.com/lander/2413018更新时间:2019/8/

vs项目模板创建和使用

一.使用dotnet命令创建(适用于.NET Core,可以创建包含任意数量个项目的模板,但不会出现在vs的新建项目模板中) 官方文档:https://docs.microsoft.com/zh-cn/dotnet/core/tools/custom-templates 拷贝所有要用作模板的项目到新建文件夹 在新建文件夹下添加./.template.config/template.json 文件 编辑template.json文件,内容如下: 1 { 2 "$schema": &quo