Asp.net reads templates and writes them to text files. asp.net templates

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.