using System; using System.Data; using System.Drawing; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.IO; using System.Collections; using System.ComponentModel; namespace ASPNetPortal { /// <summary> /// This module opens the text file and reads the text in a stream /// then it render Html code in a Browser. /// </summary> public class TextModule : ASPNetPortal.PortalModuleControl { protected System.Web.UI.WebControls.Label TextToHtmlOutPut; private void Page_Load(object sender, System.EventArgs e) { String TextSrc = (String) Settings["TextSrc"]; string TextToHtmlCode; if ((TextSrc != null) && (TextSrc != "")) { if (File.Exists(Server.MapPath(TextSrc))) { // Open the txt file string FileName = Server.MapPath(TextSrc); FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); // Read txt file to the end StreamReader r = new StreamReader(fs); TextToHtmlCode = r.ReadToEnd(); // r.Close(); fs.Close(); // Display the text from the stream TextToHtmlOutPut.Text = TextToHtmlCode; } else { Controls.Add(new LiteralControl("<" + "br" + "><" + "span class=NormalRed" + ">" + "File " + TextSrc + " not found.<" + "br" + ">")); } } } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } }