Поделиться через


File.ReadLines Method (String, Encoding)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

When it is called by trusted applications, read the lines of a file that has a specified encoding.

Namespace:  System.IO
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Shared Function ReadLines ( _
    path As String, _
    encoding As Encoding _
) As IEnumerable(Of String)
public static IEnumerable<string> ReadLines(
    string path,
    Encoding encoding
)

Parameters

Return Value

Type: System.Collections.Generic.IEnumerable<String>
The lines of the file.

Exceptions

Exception Condition
ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by the GetInvalidPathChars method.

ArgumentNullException

path is nulla null reference (Nothing in Visual Basic).

DirectoryNotFoundException

path is invalid (for example, it is on an unmapped drive).

FileNotFoundException

The file specified by path was not found.

IOException

An I/O error occurred while opening the file.

PathTooLongException

path exceeds the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters and file names must be less than 260 characters.

SecurityException

The caller does not have the required permission.

UnauthorizedAccessException

path specifies a file that is read-only.

-or-

This operation is not supported on the current platform.

-or-

path is a directory.

-or-

The caller does not have the required permission.

Remarks

For more information about trusted applications, see Trusted Applications.

Use this method to specify an encoding to use read the file.

You can use the ReadLines method to do the following:

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.