Click or drag to resize

MasterDetailEngineTMaster, TDetailWriteFile Method (String, IEnumerableMasterDetailsTMaster, TDetail)

Write an array of records to the specified file.

Namespace:  FileHelpers.MasterDetail
Assembly:  FileHelpers (in FileHelpers.dll) Version: 3.2.6
Syntax
public void WriteFile(
	string fileName,
	IEnumerable<MasterDetails<TMaster, TDetail>> records
)

Parameters

fileName
Type: SystemString
The file path to be write.
records
Type: System.Collections.GenericIEnumerableMasterDetailsTMaster, TDetail
The array of records to write.

Return Value

Type: 
True if the operation is successful. False otherwise.
Remarks

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 file.

Examples
You need to define a Selector Method too:
RecordAction ExampleSelector(string record)
{
   if (Char.IsLetter(record[0]))
      return RecordAction.Master;
    else
      return RecordAction.Detail;
}
Finally you must to instantiate a MasterDetailEngine and Read/Write files:
MaterDetailEngine engine = new MaterDetailEngine(typeof(Customers), typeof(Orders), new MasterDetailSelector(ExampleSelector));

// to Read use:
MasterDetail[] res = engine.ReadFile("TestIn.txt");

// to Write use:
engine.WriteFile("TestOut.txt", res);
See Also