Working with text files + vb.net 2005

I need to write out a text file, I used to use Print #lFileNum, text, text, text in VB6

What is the best approach now?
rocky050371Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Jorge PaulinoConnect With a Mentor IT Pro/DeveloperCommented:
The write parameter in the following sentence it's to append in your file. You can always add line by line
My.Computer.FileSystem.WriteAllText("c:\yourfile.txt", "text", True)

To read line by line you can do
Dm fileinfo() As String
fileinfo = My.Computer.FileSystem.ReadAllText("c:\yourfile.txt")
For x As Integer = 0 To fileinfo.Lenght-1
  MsgBox(fileinfo(x))
Next x

jpaulino
0
 
Jai STech ArchCommented:
you can us a stream writer object

        Dim st As StreamWriter = New StreamWriter("c:\dd.txt", True)
        st.Write("you value")
        st.Close()
0
 
peetmCommented:
The FileSystemObject [Microsoft Scripting Runtime] is what I always use - good support for anything other than binary files.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Jorge PaulinoIT Pro/DeveloperCommented:
If you like to follow the Microsoft example (snippets) using the new My Class ...

' Read
Dim fileinfo As String
fileinfo = My.Computer.FileSystem.ReadAllText("c:\yourfile.txt")

' Write
My.Computer.FileSystem.WriteAllText("c:\yourfile.txt", "text", True)

jpaulino
0
 
rocky050371Author Commented:
I need to write it out line by line. The document may have several hundred lines, is this still the best way of achieving it
0
 
Fernando SotoConnect With a Mentor RetiredCommented:
Hi rocky050371;

Imports System.IO

' Open the file up for writing
Dim sw As StreamWriter = New StreamWriter("c:\MyDirectory/MyFile.txt")

To write to the file:

Dim LineOfData As String = "Data to be written to the file"
' Write to the file with no line terminator
sw.Write( LineOfData )

' Or write to the file with line terminator
sw.WriteLine( LineOfData )

' When you are done with the file close it.
sw.Close( )

Fernando
0
 
Bob LearnedConnect With a Mentor Commented:
System.IO.File.WriteAllLines(fileName, contents)

Bob
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
All Courses

From novice to tech pro — start learning today.