Click or drag to resize

FileInfoOpenText Method

Creates a StreamReader with UTF8 encoding that reads from an existing text file.

Namespace: Crestron.SimplSharp.CrestronIO
Assembly: SimplSharpHelperInterface (in SimplSharpHelperInterface.dll) Version: 2.21.121
Syntax
C#
public StreamReader OpenText()

Return Value

StreamReader
A new StreamReader with UTF8 encoding.
Exceptions
ExceptionCondition
DirectoryNotFoundExceptionInvalid directory location.
FileNotFoundExceptionThe file passed does not exist.
SecurityExceptionThe user does not have the required permissions.
UnauthorizedAccessExceptionAttempt to copy a file to a different drive.
Example
using Crestron.SimplSharp; using Crestron.SimplSharp.CrestronIO;; class Test { public static void Main() { string path = @"\User\MyTest.txt"; FileInfo fi = new FileInfo(path); // Check for existing file if (!fi.Exists) { // Create the file. using (FileStream fs = fi.Create()) { Byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file."); // Add some information to the file. fs.Write(info, 0, info.Length); fs.Close(); } } // Open the stream and read it back. using (StreamReader sr = fi.OpenText()) { string s = ""; while ((s = sr.ReadLine()) != null) { Process ..... } } } }

Version Information

.NET

Supported in: 6.0

.NET Compact Framework

Supported in: 3.5
See Also