• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2365
  • Last Modified:

How to write out a text stream in VB.NET

Hi,

I want to write out a text stream in VB.NET and I tried this approach. The system doesn't like it because I am trying to write a character to a byte stream

Sub writeMyFile(ByVal path As String, ByVal content As String)
        Dim i As Long
        Dim myWriter As New System.IO.FileStream(path, IO.FileMode.Create)
        For i = 0 To content.Length - 1
                  myWriter.WriteByte(content.Chars(i))
        Next
        myWriter.Close()
    End Sub
end sub
0
Christopher Schene
Asked:
Christopher Schene
1 Solution
 
nayernaguibCommented:
This should work:

    Sub writeMyFile(ByVal path As String, ByVal content As String)
        Dim myWriter As New System.IO.FileStream(path, IO.FileMode.Create)
        myWriter.Write(New System.Text.ASCIIEncoding().GetBytes(content), 0, content.Length)
        myWriter.Close()
    End Sub

_______________

  Nayer Naguib
0
 
Christopher ScheneSystem Engineer/Software EngineerAuthor Commented:
Works great! Thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now