File::AppendAllLines Method (String^, IEnumerable<String^>^)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Appends lines to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file.

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

static void AppendAllLines(
	String^ path,
	IEnumerable<String^>^ contents


Type: System::String^

The file to append the lines to. The file is created if it doesn't already exist.

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

The lines to append to the file.

Exception Condition

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


Either path or contents is null.


path is invalid (for example, the directory doesn’t exist or it is on an unmapped drive).


The file specified by path was not found.


An I/O error occurred while opening the file.


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.


path is in an invalid format.


The caller does not have permission to write to the file.


path specifies a file that is read-only.


This operation is not supported on the current platform.


path is a directory.

The method creates the file if it doesn’t exist, but it doesn't create new directories. Therefore, the value of the path parameter must contain existing directories.

The following example writes selected lines from a sample data file to a file, and then appends more lines. The directory named temp on drive C must exist for the example to complete successfully.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 10
.NET Framework
Available since 4.0
Available since 4.0
Return to top