Click or drag to resize

FileInfoOpen(FileMode) Method

Opens a file in the specified mode.

Namespace: Crestron.SimplSharp.CrestronIO
Assembly: SimplSharpHelperInterface (in SimplSharpHelperInterface.dll) Version: 2.21.121
Syntax
C#
public FileStream Open(
	FileMode mode
)

Parameters

mode  FileMode
Specified mode to open the file. (Open, Append, etc.)

Return Value

FileStream
A file opened in the specified mode, with read/write access and unshared.
Exceptions
ExceptionCondition
InvalidDirectoryLocationExceptionInvalid directory location passed.
IOExceptionFile System error while attempting to open the stream.
DirectoryNotFoundExceptionInvalid directory location.
FileNotFoundExceptionThe file passed does not exist.
PathTooLongExceptionPath is great than 248 characters.
ArgumentExceptionInvalid argument passed.
ArgumentNullExceptionOne of the arguments is null.
SecurityExceptionThe user does not have the required permissions.
ArgumentOutOfRangeExceptionMode or FileAccess are invalid.
NotSupportedExceptionThe file is of a non-file system type.
Example
using Crestron.SimplSharp; using Crestron.SimplSharp.CrestronIO;; class Test { public static void Main() { string path = @"\User\MyTest.txt"; FileInfo fi = new FileInfo(path); // Delete the file if it exists. 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); } } //Open the stream and read it back. using (FileStream fs = fi.Open(FileMode.Open)) { byte[] b = new byte[1024]; UTF8Encoding temp = new UTF8Encoding(true); while (fs.Read(b, 0, b.Length) > 0) { ...... } } } }

Version Information

.NET

Supported in: 6.0

.NET Compact Framework

Supported in: 3.5
See Also