Click or drag to resize

FileInfoCreateText Method

Creates a StreamWriter that writes a new text file.

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

Return Value

StreamWriter
A new StreamWriter.
Exceptions
ExceptionCondition
IOExceptionFile system error.
UnauthorizedAccessExceptionAttempt to copy a file to a different drive.
SecurityExceptionThe user does not have the required permissions.
Example
using Crestron.SimplSharp; using Crestron.SimplSharp.CrestronIO;; class Test { public static void Main() { string path = @"c:\MyTest.txt"; FileInfo fi = new FileInfo(path); // Delete the file if it exists. if (fi.Exists) { fi.Delete(); } //Create the file. using (FileStream fs = fi.CreateText()) { Byte[] info = new UTF8Encoding(true).GetBytes("This is some text for the file."); //Add some information to the file. fs.Write(info, 0, info.Length); } } }

Version Information

.NET

Supported in: 6.0

.NET Compact Framework

Supported in: 3.5
See Also