Create file from a template file

Template file in html Format
Template.html
<html>
<head><title>Template</title>
<head>
<body>
  <p>Name: {name}</p>
  <p>Address: {address}</p>
  <p>Telephone: {phone}</p>
</body>
</html>
default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>

<!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 runat="server">
    <title>Template</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
          <asp:Button ID="btnSubmit" Text="Create From Template" OnClick="btnSubmit_Click" runat="server" />
    </div>
    </form>
</body>
</html>
default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
                  
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        List<string> lstColumns = new List<string>();
        //- File Info
        lstColumns.Add("{name}"); //-name - 1
        lstColumns.Add("{address}"); //-address - 2
        lstColumns.Add("{phone}"); //-telephone - 3                

        //- File Data Value                                                                
        List<string> lstColumnsData = new List<string>();
        lstColumnsData.Add("John Doe");   //- name data
        lstColumnsData.Add("123 Somewhere in US, NY, NY 10005");  //- address data
        lstColumnsData.Add("212-555-5555"); //- phone data

        ncTools.FilesHelper oCreateDoc = new ncTools.FilesHelper();
        oCreateDoc.SourceFolderPath = "~/templates/"; //- path-folder where your template.html will be located
        oCreateDoc.TargetFolderPath = "~/export/";   //- path-folder where file will be created
        //- Create the file
        oCreateDoc.CreateFileFromTemplate(lstColumns, lstColumnsData, "template.html", ncTools.eFileTypes.Html, "mycrated_doc_");
        //- If file is created then display it.
        ncTools.DFO.TheFileHandler("~/export/" + oCreateDoc.Created_FileName.Trim(), "");        
    }
}
Download .DLL Library here ncTools.zip (FREE to use commercial)

Add Feedback