'How to generate a text file in asp.net core (Razor) by using a static text template

I want to generate a file in ASP.Net Core using a pre-defined template. The template has several variables which has to be replaced by the values in the generated file. Template has "%" wildcard to identify the variable. For example, In the attached image, %SITECODE% should be replaced by the actual value.

TemplateFile



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source