Send text file to client : Write « Response « ASP.NET Tutorial






<%@ Page %>
<%@ Import Namespace="System.IO" %>
<script language="C#" runat="server">
  void Page_Load(object sender, EventArgs e)
  {
    ReadReversed();
  }
  
  private void ReadReversed()
  {        
    StreamReader sr = null;
    string text;
    string[] lines = {null};
    
    try
    {
      sr = File.OpenText(Server.MapPath("textFile.txt"));
      text = sr.ReadToEnd();
      lines = text.Split('\n');
      sr.Close();

      for (int i=lines.Length-1;0<=i;i--)
      {
        HttpContext.Current.Response.Write(lines[i].ToString());
        HttpContext.Current.Response.Write("<br />");
      }
    }
    catch (Exception exc)
    {
      HttpContext.Current.Response.Write(exc.Message);
    }
    finally
    {
      if (sr != null)
        sr.Close();
    }      
  }
</script>








6.4.Write
6.4.1.Use Response.Write to output message based on HTML tags (VB.net)
6.4.2.Calculation in Response.Write (VB)
6.4.3.Calculation in Response.Write (C#)
6.4.4.Output integer and string in Response.Write
6.4.5.Output HTML tags in Response.Write, change the tag properties dynamicallys (VB.net)
6.4.6.Create Client Side MessageBox
6.4.7.Send text file to client