hi thisis my first post here, what i need to know is how to read/write files using visual basic 9
(visual studio 2008)

its different in vb6 and vstudio
for
open (text) as (int) for output

for those who have or r familiar with vstudio 2008, i took the "windows application" with awindows interface
its showing something else... says just I/O...
could u please tell me the code 2 read/write files using visual studio...

put this code in top of codes :

Imports System.IO

This following code is function to write and open file :

Public Function GetFileContents(ByVal FullPath As String, _
           Optional ByRef ErrInfo As String = "") As String

        Dim strContents As String
        Dim objReader As StreamReader
        Try

            objReader = New StreamReader(FullPath)
            strContents = objReader.ReadToEnd()
            objReader.Close()
            Return strContents
        Catch Ex As Exception
            ErrInfo = Ex.Message
        End Try
End Function

Public Function SaveTextToFile(ByVal strData As String, _
     ByVal FullPath As String, _
       Optional ByVal ErrInfo As String = "") As Boolean

        Dim Contents As String
        Dim bAns As Boolean = False
        Dim objReader As StreamWriter
        Try


            objReader = New StreamWriter(FullPath)
            objReader.Write(strData)
            objReader.Close()
            bAns = True
        Catch Ex As Exception
            ErrInfo = Ex.Message

        End Try
        Return bAns
End Function

Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
    TextBox1.Text = GetFileContents("D:\Jx_Man2.txt")
End Sub

Private Sub btnWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWrite.Click
    SaveTextToFile(TextBox1.Text, "D:\Jx_Man2.txt")
End Sub
This article has been dead for over six months. Start a new discussion instead.