File.ReadLines Method (String)
When it is called by trusted applications, reads the lines of a file.
Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Parameters
- path
- Type: System.String
The file to read.
| Exception | Condition |
|---|---|
| ArgumentException |
path is a zero-length string, contains only white space, or contains one or more invalid characters 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.
You can use the ReadLines method to do the following:
-
Perform queries on a file to obtain a filtered set of its lines.
-
Write the returned collection of lines to a file with the File.WriteAllLines(String, IEnumerable<String>) method, or append them to an existing file with the File.AppendAllLines(String, IEnumerable<String>) method.
-
Create an immediately populated instance of a collection that takes an IEnumerable<T> collection of strings for its constructor, such as a IList<T> or a Queue<T>.
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.