Export (0) Print
Expand All

File::WriteAllLines Method (String, IEnumerable<String>, Encoding)

Creates a new file by using the specified encoding, writes a collection of strings to the file, and then closes the file.

Namespace:  System.IO
Assembly:  mscorlib (in mscorlib.dll)

public:
static void WriteAllLines(
	String^ path, 
	IEnumerable<String^>^ contents, 
	Encoding^ encoding
)

Parameters

path
Type: System::String

The file to write to.

contents
Type: System.Collections.Generic::IEnumerable<String>

The lines to write to the file.

encoding
Type: System.Text::Encoding

The character encoding to use.

ExceptionCondition
ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters defined by the GetInvalidPathChars method.

ArgumentNullException

Either path, contents, or encoding is nullptr.

DirectoryNotFoundException

path is invalid (for example, it is on an unmapped drive).

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.

NotSupportedException

path is in an invalid format.

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.

If the target file already exists, it is overwritten.

You can use this method to create a file that contains the following:

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft