Home DotNet How to Read Text/XML File into StringBuilder in ASP.NET
Author:

If you need to do some manipulation to your text/xml file then you could read the text from the file into the StringBuilder object.

You can use the StreamReader object to do this, and it is simple. Here's how:

Imports System.Text

Imports System.IO

 

Partial Class _Default

    Inherits System.Web.UI.Page

 

 

    Public Sub New()

        'Read text file or xml file into the string builder object

 

        Dim filePath As String = Server.MapPath("~/") & "smithc.xml"

        Dim resultsBuilder As StringBuilder = New StringBuilder()

        'Dim sbSmith As StringBuilder = New StringBuilder

        Dim sReader As StreamReader = New StreamReader(filePath)

        Dim line As String

 

        Do

            line = sReader.ReadLine()

            resultsBuilder.Append(line)

        Loop Until line Is Nothing

        sReader.Close()

 

        Response.ContentType = "text/xml"

        Response.Write(resultsBuilder.ToString())

    End Sub

End Class



Comments (3)
  • Angre Hassan  - Import text document to stringbuilder object the e
    If you need to read a text document into a stringbuilder object, Stringstrong is a convenient utility. It is free to try, and not expensive to buy. I use String strong to prototyping .aspx and also for making text rich dialogs in VB. :D
  • Zishanali Tailor  - Suggestion
    Hello. this is a rubbish solution
  • admin
    Zizhanali - This solution works. Plain simple. If you have something better you are welcome to post it here.
Write comment
Your Contact Details:
Comment:
Security
Please input the anti-spam code that you can read in the image.

"