Asp.net reads templates and writes them to text files. asp.net templates
This article describes how ASP. NET reads and writes text files, but more importantly, the implementation process. The tool used is Visual Studio 2015 and the. NET version is 4.6.1. Two projects, HoverTreePanel and HoverTreeWeb, are both ASP. NET projects. Download the source code at the end of the article.
Project results include:
The hosts file is a template. The program will read the content of the file, replace [HoverTreeText/hosts in the template with the input content, and generate the final result index.htm file in the root directory of the HoverTreeWeb project.
The main implementation is in the btnHovertree_Click method of GeneratePage. aspx. cs on the GeneratePage. aspx page.
The interface is as follows:
Run the HoverTreeWeb project as follows:
Code for the btnHovertree_Click method:
Protected void btnHovertree_Click (object sender, EventArgs e) {StreamReader h_hovertreeSr = new StreamReader (System. web. httpContext. current. request. mapPath ("HoverTreeTemplate.html"); string h_hovertreeTemplate = extract (); // read the template content h_hovertreeSr.Close (); // the physical path of the current website root directory DirectoryInfo h_dir = new DirectoryInfo (System. web. httpContext. current. request. physicalApplicationPath); // HoverTre The main page file string h_path = h_dir.Parent.FullName + "\ HoverTreeWeb \ index.htm" under the root directory of the eWeb project; StreamWriter h_sw = new StreamWriter (h_path, false, Encoding. UTF8); h_sw.Write (h_hovertreeTemplate.Replace ("[HoverTreeText/]", tbHovertree. text); h_sw.Close (); ltlTips. text = "generation time:" + DateTime. now. toString () + ", run the HoverTreeWeb project to view the effect. ";}
The code for the HoverTreeTemplate.html file is as follows:
<! DOCTYPE html>
Download source code:
Http://hovertree.com/h/bjaf/0ofallum.htm