I want to write a csv file in the append mode in vb .net 2010

I want to write a csv file in the append mode in vb .net 2010
1030071002Asked:
Who is Participating?
 
1030071002Connect With a Mentor Author Commented:
other wise from using om_prakash_p method which he suggest using StreamWriter
Dim path As String = "c:\temp\MyTest.txt"
        Dim sw As StreamWriter
 
        ' This text is added only once to the file.
        If File.Exists(path) = False Then
            ' Create a file to write to.
            sw = File.CreateText(path)
 
            sw.WriteLine("Hello")
            sw.WriteLine("And")
            sw.WriteLine("Welcome")
            sw.Flush()
            sw.Close()
        End If
 
        ' This text is always added, making the file longer over time
        ' if it is not deleted.
        sw = File.AppendText(path)
        sw.WriteLine("This")
        sw.WriteLine("is Extra")
        sw.WriteLine("Text")
        sw.Flush()
        sw.Close()
 
 
0
 
Jorge PaulinoConnect With a Mentor IT Pro/DeveloperCommented:
You can use a streamwriter.
http://dotnetperls.com/streamwriter-vbnet 
0
 
Om PrakashConnect With a Mentor Commented:

Dim path As String = "c:\temp\MyTest.txt"
        Dim sw As StreamWriter

        ' This text is added only once to the file.
        If File.Exists(path) = False Then
            ' Create a file to write to.
            sw = File.CreateText(path)

            sw.WriteLine("Hello")
            sw.WriteLine("And")
            sw.WriteLine("Welcome")
            sw.Flush()
            sw.Close()
        End If

        ' This text is always added, making the file longer over time
        ' if it is not deleted.
        sw = File.AppendText(path)
        sw.WriteLine("This")
        sw.WriteLine("is Extra")
        sw.WriteLine("Text")
        sw.Flush()
        sw.Close()

        ' Open the file to read from.
        Dim sr As StreamReader = File.OpenText(path)
        Dim s As String
        Do While sr.Peek() >= 0
            s = sr.ReadLine()
            Console.WriteLine(s)
        Loop
        sr.Close()

Open in new window

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
1030071002Author Commented:
is there any other way to write or append text in vb .net
0
 
Jorge PaulinoConnect With a Mentor IT Pro/DeveloperCommented:
>> is there any other way to write or append text in vb .net
What do you mean with that?
0
 
Jorge PaulinoConnect With a Mentor IT Pro/DeveloperCommented:
I also suggested a StreamWriter :)
You have other ways to do that, but you need that for?
You can use also:

My.Computer.FileSystem.WriteAllText("c:\myText.txt","some text",True) ' True = append method
IO.File.WriteAllText("c:\myText.txt", "some text")
0
 
1030071002Author Commented:
is this file system object

'loop to read & write to file
Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
Dim buffer(2047) As Byte
Dim read As Integer = 0
Do
read = responseStream.Read(buffer, 0, buffer.Length)
fs.Write(buffer, 0, read)
Loop Until read = 0 'see Note(1)
0
All Courses

From novice to tech pro — start learning today.