Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to Create reporting tool that reads any data files in different formats and creates an output file in CSV format using Console application .
Posted

One approach is to create an abstract base class with methods used to read a file.
For example:
C#
public abstract class FileReaderBase
{
    public FileReaderBase()
    {
    }
    
    public abstract MyOutputFormat Parse(string inputFileName);
    
}

Then create a class per format that inherits from the abstract base class.

Also create an output format to be used to save data in a CSV file.
 
Share this answer
 
that's a big question - I'd suggest you start looking at this A Portable and Efficient Generic Parser for Flat Files[^] (and similar articles) if you really want to write one from scratch - its not difficult

Conceptually you need to

a) recognise each type of file
b) implement an Interface for a parser that can read the file type into an internal format
c) optionally map the input fields to the required output csv - not all fields in the input may be used for example, or re-ordered (I'd possibly use xml to describe the input file, mappings, and output file)
d) implement a csv output stage using (c)

there are 'EDI' translate engines for example that do all/some of what your asking - but many of these cost $$

btw - have you thought about a tool like Crystal reports or looked around and found something that you can drive/automate ?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900