Click or drag to resize

IFileHelperEngineTWriteFile Method (String, IEnumerableT, Int32)

Write the specified number of records from the array to a file.

Namespace:  FileHelpers
Assembly:  FileHelpers (in FileHelpers.dll) Version: 3.2.6
void WriteFile(
	string fileName,
	IEnumerable<T> records,
	int maxRecords


Type: SystemString
The file path to be write.
Type: System.Collections.GenericIEnumerableT
The records to write (Can be an array, ArrayList, etc)
Type: SystemInt32
The max number of array elements to write.

Return Value

True if the operation is successful. False otherwise.

This method opens, writes and closes the file (don't open or close the file before or after calling this method)

This method over writes any existing files.

This example shows a simple example of use of the library with a minimum of code:
using FileHelpers;

// First declare the record class

public class SampleType
    public string Field1;
    public int    Field2;

public void WriteExample()
    var engine = new FileHelperEngine<SampleType>();

    SampleType[] records = new SampleType[1];

    records[0] = new SampleType();

    records[0].Field1 = "Hello World";
    records[0].Field2 = 12;

    engine.WriteFile("destination.txt", records);

    // Now the file contains the created record in this format:
    // Hello World,12

See Also