Create file from a template file

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
          <asp:Button ID="btnSubmit" Text="Create From Template" OnClick="btnSubmit_Click" runat="server" />
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 (FREE to use commercial)

Add Feedback