Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I need to load a pre defined letter template when a new view loads and fill data(data comes from a stored procedure) for some fields on the letter(like from address , to address, date, etc...).
Any kind of help is appreciated.
Posted

1 solution

Hello Donthi
Here is the code sample for your problem, but in C# and ASP.Net

suppose your template is as below
XML
<table>
   <tr>
    <td>
      <strong>Dear **FullName**</strong>
    </td>
   </tr>
</table>


in the file Template.html
Now you want to show this template on another page Default.aspx

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div runat="server" id="dv">

    </div>
    </form>
</body>
</html>


on the code behind page write the following code

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
          string filetoread = string.Empty;
          filetoread  = Server.MapPath("~/Template.html");// load the pre   defined letter template
          StreamReader filestream =  (StreamReader)File.OpenText(filetoread);// Load the file into stream
         if (filestream != null)
          {
           string ReadContents = filestream.ReadToEnd();// read the stream from current position to the end of the stream
           filestream.Close();// close stream
           string FinalDoc = ReadContents.Replace("**FullName**", "Rajneesh");//Here you can can sent your own content from Stored Procedure
          }
          dv.InnerText = FinalDoc ;// your template would be loaded into div
        }
    }
}


this is just an example. hope it would help you to solve your problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900