ReadAllText Method


ReadAllText Method

Location

My.Computer.FileSystem.ReadAllText

Syntax

     Dim result As String = My.Computer.FileSystem.ReadAllText( _     path[, encoding]) 


path (required; String)

The path of the file to read.


encoding (optional; Encoding)

The character-encoding method to use as a System.Text.Encoding object. If this parameter is missing, UTF-8 is used as the default encoding method.

Description

The ReadAllText method returns the entire contents of a text file as a String. For information on code pages and encoding, see the System.Text.Encoding entry in the documentation supplied with the .NET Framework.

Usage at a Glance

  • An exception is thrown if the path parameter is missing or invalid or if the file it refers to does not exist.

  • An exception is thrown if the user lacks sufficient file-access permissions.

  • An exception is thrown if the file content is too large for available memory.

Example

The following example reads in the contents of a file.

     Dim errorText As String     errorText = My.Computer.FileSystem.ReadAllText("C:\error.log")     If (Len(Trim(errorText)) <> 0) Then _        MsgBox("The following error was recorded:" & vbCrLf & _        vbCrLf & errorText) 

Related Framework Entries

  • Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText Method

  • Microsoft.VisualBasic.MyServices.FileSystemProxy.ReadAllText Method

See Also

FileSystem Object, OpenTextFieldParser Method, OpenTextFileReader Method, OpenTextFileWriter Method, ReadAllBytes Method, WriteAllBytes Method, WriteAllText Method




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net