
602
|
Chapter 13: The ‘My’ Reference
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
See Also
FileSystem Object, OpenTextFieldParser Method, OpenTextFileReader Method,
OpenTextFileWriter Method, ReadAllText Method, WriteAllBytes Method, WriteAll-
Text 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 infor-
mation 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 ...