Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

File.ReadLines Method (String, Encoding)

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)

public static IEnumerable<string> ReadLines(
	string path,
	Encoding encoding
)

Parameters

path
Type: System.String
The file to read.
encoding
Type: System.Text.Encoding
The encoding that is applied to the contents of the file.

Return Value

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

ExceptionCondition
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 null.

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.

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:

Silverlight

Supported in: 5, 4

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

Community Additions

Show:
© 2014 Microsoft