Wednesday, August 23, 2006

Page content from a file ASP.NET

First create a textfile with HTML code in it (or just plain Text)

Create a class to read the stuff from files

public class LearningProvider
{

string templatedirectory=System.Web.HttpContext.Current.Server.MapPath("/NAALearningProvider/Controls/_Templates/Content/");
public LearningProvider()
{
//
// TODO: Add constructor logic here
//
}
public string ReadTemplate(string templateFile)
{
StreamReader streamReader=new StreamReader(templatedirectory+templateFile+".txt");
return Regex.Replace(streamReader.ReadToEnd(),"\r\n","
");

}
}

Now use this code to use class from the ASPX page

LearningProvider lp=new LearningProvider();
lblContent.Text = lp.ReadTemplate("LPUpdateDetailsConfirm");

No comments: