Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse routines to easily read and write a file's contents in VB .NET
DescriptionThis example shows how to use routines to easily read and write a file's contents in Visual Basic .NET.
Keywordsstar, polygon, VB.NET
CategoriesFiles and Directories, VB.NET
 
Function GetFileContents creates a StreamReader attached to the file and uses its ReadToEnd method to read the file. It closes the StreamReader and returns the file's contents.
 
' Return a file's contents.
Private Function GetFileContents(ByVal file_name As String) _
    As String
    Dim stream_reader As New IO.StreamReader(file_name)
    Dim txt As String = stream_reader.ReadToEnd()
    stream_reader.Close()
    Return txt
End Function
 
Subroutine SetFileContents creates a StreamWriter attached to the file, uses its Write method to write the file, and then calls its Close method.
 
' Set a file's contents.
Private Sub SetFileContents(ByVal file_name As String, _
    ByVal contents As String)
    Dim stream_writer As New IO.StreamWriter(file_name, _
        False)
    stream_writer.Write(contents)
    stream_writer.Close()
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated