How often did you have to read data separated, for example, by a comma (CSV format) from a file, process it and do something further with them?

    Of course you can write the code yourself, but it will take time and not always be effective.

    FileHelpers - a module that will help you. It can synchronously or asynchronously read data from a file into an object. It can also enter data back into the file with the specified delimiter. Can read data from a database. It has a bunch of all sorts of features, which can be found in more detail on the official website of this module.

    Example of asynchronously reading data from a file

    Suppose you have the following file with data separated by the "|" symbol:
    10248 | VINET | 04071996 | 32.38
    10249 | TOMSP | 05071996 | 11.61
    10250 | HANAR | 08071996 | 65.83
    10251 | VICTE | 08071996 | 41.34

    You need to create a class that describes the file data structure:
     [DelimitedRecord ("|")] // Define the separator
     public class Orders
       public int OrderID;

       public string CustomerID;

       [FieldConverter (ConverterKind.Date, "ddMMyyyy")]
       public DateTime OrderDate;

       public decimal Freight;
     } * This source code was highlighted with Source Code Highlighter .

    Now read the data asynchronously:
      FileHelperAsyncEngine engine = new FileHelperAsyncEngine (typeof (Orders));

      engine.BeginReadFile ("TestIn.txt");

      // The engine is IEnumerable
      foreach (Orders ord in engine)
        // your code here
        Console.WriteLine (ord.CustomerID);

      engine.Close ();
    * This source code was highlighted with Source Code Highlighter .

    That's all.


    Download FileHelpers v2.0 from here .

    Also popular now: