Skip to content
October 8, 2006 / jphoward

FileHelpers Library

The FileHelpers Library is an elegantly designed, thoroughly tested, free (LGPL) library for .Net, described by its author as

…an easy to use library to import/export data from fixed length or delimited records in files, strings or streams.

Here’s an example from the project’s web site to read and write delimited text files:

[DelimitedRecord(“,”)] public class Customer {

    public int CustId;

    public string Name;

    public decimal Balance;

    [FieldConverter(ConverterKind.Date, “dd-MM-yyyy”)]

    public DateTime AddedDate;

}

 

internal class Program {

    private static void Main(string[] args) {

        FileHelperEngine<Customer> engine = new FileHelperEngine<Customer>();

        // To Read Use:

        Customer[] res = engine.ReadFile(“FileIn.txt”);

        foreach (Customer cust in res) {

            Console.WriteLine(“Customer Info:”);

            Console.WriteLine(cust.Name + ” – “ +

                              cust.AddedDate.ToString(“dd/MM/yy”));

        }

 

        // To Write Use:

        engine.WriteFile(“FileOut.txt”, res);

    }

}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: