|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Announcements
Chapters
Feature Zones
|
FileHelpers Home Page (Project Summary) FileHelpers v 2.0IntroductionThe FileHelpers are an easy to use library to import/export data from fixed length or delimited flat files (like the CSV). FileHelpers also has support to import/export data from different data storages (Excel, Acces, SqlServer). The library has a set of converters for the basic types and can be easily extended to provide custom converters. The main idea is pretty simple: You can strong type your flat file (fixed or delimited) simply describing a class that maps to each record of the file and work with your file like a strong typed .NET array. Basic UsesDirectly between the files and the .NET source code: It also can be used as an intermediate between files and MS Access or MS SqlServer tables: Quick Start Guide (easy steps)
To start using the FileHelpers Library you only need to add a reference in your project to the file: FileHelpers.dll. You can find it in the Release directory of the distribution. Tip: remember to leave the FileHelpers.xml file to get Intellisense support. Next you need to define a class that maps to the record in the source/detination file. For this example we use a file with this format delimited by a |: 10248|VINET|04071996|32.38
10249|TOMSP|05071996|11.61
10250|HANAR|08071996|65.83
10251|VICTE|08071996|41.34
...............
The class that we refer can be like this: [DelimitedRecord("|")]
public class Orders
{
public int OrderID;
public string CustomerID;
[FieldConverter(ConverterKind.Date, "ddMMyyyy")]
public DateTime OrderDate;
public decimal Freight;
}
Later you must instantiate a FileHelperEngine and Read/Write files: FileHelperEngine engine = new FileHelperEngine(typeof(Orders));
/// to Read use:
Orders[] res = (Orders[]) engine.ReadFile("input.txt");
/// to Write use:
engine.WriteFile("output.txt", res);
Finally you can use the res array to access each item in the file, for example: foreach (Orders order in res)
{
Console.WriteLine("Order Info:");
Console.WriteLine(order.CustomerID + " - " +
order.OrderDate.ToString("dd/MM/yy"));
}
Working with FixedLength files is exactly the same but you need to use the [FixedLengthRecord] and [FieldFixedLength] attributes. Record Class WizardSince version 1.3.5 the library has had a Record Class Wizard to generate the record class. The Record Class Wizard allows you to generate your record mapping class, save the definition, generate code based on snippets (Read File, Read with Generics, ReadAsync and so on). The wizard uses the excellent FireBall CodeEditor Who needs the File Helpers Library?In almost every project there is a need to read/write data from/to a flat file of a specified format. Writing the code to process these files is not hard, you can use So with the FileHelpers you don't need to worry about changes in the file structure because you can change the Type, Converters, Triming, Length in seconds. Another place where you can find the FileHelpers useful is for log parsing, data warehouse and OLAP applications, communication between systems, file format transformations (for example from a fixed length to an CSV file), load test data into your NUnit tests and a lot more!!! This library aims to provide an easy and reliable way to accomplish all these tasks. Main FeaturesEasy to use: The FileHelpers Lib is straight forward to learn and use. (see EasyExample) Auto Converters: The library has a set of converters for the basic types and can be easy extended to provide custom converters. (see ConverterBase and Converter Example) RunTime Classes since version 1.6.0 you have been able to create your record class at run time, and load them from files with source code or an XML description (check the example) Master-Detail: You can read and write records with a master/detail pattern. (see Example1 and Example2) Multiple record format support: With the Event Support: The engines of the library contain some events to allow you to easily extend the behavior of the library (see Example) MS Excel Storage: Are a way to extract / insert records between any source and an excel file. (see ExcelDataStorage and ExcelDataLinkExample) DataLinks: Are a way to extract / insert records between a database and a file. (see DataStorage and FileDataLinkExample) GenericDataLink: Now you can to copy records between two Data Storages (see GenericDataLink and DataStorage) Asynchronous Mode: You can use the library to read line by line and not the whole file. (see Async Methods) .NET Compact Framework Support: From the version 1.1 you can use the FileHelpers library for you PocketPC and WindowsCE developments. (thanks Pierre) File Transform Engine: To convert files in one format to another (for example a file with CSV to a Progress Notification: To get notified of the progress in each operation in the library (check the example) .NET 2.0 Generics: the cast less and strong typed version of the engines (check the example) FileDiffEngine to allow compare files with the same record layout (check the example) Others FeaturesFiles, Stream and String Support: You can use the library to read/write any stream or string, not only files. (see FileHelperEngine) Different Error Behaviors: You can set the behavior of the library when an error is found (throw and exception, ignore, save and continue, etc) (see the examples) Quoted String Support: It allows to indicates that the field must be read and written as Quoted String, like Excel CSV. (see FieldQuotedAttribute ) CommonEngine a easy way to access to common operations (check the example) Encoding Aware: You can define the encoding used to read and write files or streams. (see BaseEngine.Encoding) NullValues: The library identifies the null values in the files and assigns an adequate value. (see FieldNullValueAttribute) Good Documentation: The library is fully documented (at least that's the intention) with a lot of Examples of Use. Align and Trimming: You can set the processing mode of the in/out strings with a lot of attributes like the FieldAlignAttribute and the FieldTrimAttribute. Progress NotificationHere is a screenshot of the progress notification of the demo app. Since versión 1.4.0 you can get notified of the progress of each operation of the library to show feedback to the user or whatever you want. Class DiagramDetailed DiagramTestingThe library contains more than 250 NUnit tests to ensure correctness:
HistoryVersion 2.0 (April-2007)The library has passed his 1st birthday!!! Thank you all for your work and contributions (partial list of them) A lot of things were changed (mostly internally), now we have a performance gain of more than 60% for .NET 2.0 I keep releasing the .NET 1.1 version because I know that a lot of people use it in some corportaions, but it could be that new features in the versions to come will be .NET 2.0 only. It is monumental work to maintain and optimize both versions. There are also a lot of major changes, a lot of refactoring in the code, and a big core rewrite that allows the engines to use less memory and temporary strings (we are using more buffers to aviod this) I keep working hard to keep the library updated and give support to the users. You can check for examples in the Forums which shows a lot of problems that have been solved. I also ask for a lot of mail with problems from the users. We have our own domain www.filehelpers.com thanks to (Antoine) and a Development Blog Breaking Changes
Performance Related
Shining new features
API Changes and Extensions
Small Changes
Browse the complete history at SourceForge. RoadMap (the future of the lib)Check it out at SourceForge FileHelpers Roadmap. Contact and IdeasThe main site of contact of the library are the FileHelpers Forums If you find that there is a feature that I must include, or you have a new idea (for the API, Source Code or Examples), only let me know, entering the forums or sending an e-mail to marcos[at]filehelpers.com Licence (LGPL)FileHelpers Library is @Copyright 2005-2006 to Marcos Meli but it's source code and the binaries are free for commercial and non commercial use. Vote for this article if you like the library. About the Author
General comment News / Info Question Answer Joke / Game Admin message
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ASP Alliance • Developer Fusion • Developersdex • DevGuru • Programmers Heaven • Planet Source Code • Tek-Tips Forums |