How to open text file in ASP.NET

by Waqas 6/6/2008 5:13:00 PM

Here is a code snippet to address a common problem to use simple text files using System.IO in ASP.NET:

        'Open a file for reading
        Dim FILENAME As String = Server.MapPath("Data.txt")

        'Get a StreamReader class
        Dim objStreamReader As System.IO.StreamReader
        objStreamReader = System.IO.File.OpenText(FILENAME)

        'Read the entire file into a string
        Dim contents As String = objStreamReader.ReadToEnd()

        'Optionally you may wish to replace carraige returns with <br>s
        TextBox1.Text = contents.Replace(vbCrLf, "<br>")

        objStreamReader.Close()

Hope it helps!

Currently rated 1.0 by 1 people

  • Currently 1/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

How To

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading




Tags

© Copyright Beyond Web Logs.


Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in