Reputation: 9
I have to create a fix length record file using C#. I read the records from database and then after some business logic I would like to write some of the fields into a text file. I researched this and some recommend using an XML to define the file, while others format the string and then write that into a file.
Is there a proper way to do this? I would like to keep this object oriented.
Thanks for any hints.
Upvotes: 0
Views: 2157
Reputation: 5234
In the past when i've done this, I pull the data out of SQL as a Char(Length) so that the padding is handled by SQL. This makes the C# pretty easy to put together. You can do this by casting or converting the data when you select it, or by creating a table that is the exact format of your file and inserting the data in there before pulling it out into C#.
Upvotes: 0
Reputation: 63
You can use Jet to parse fixed length records in a text file. This is a decent overview that should be able to get you started:
http://msmvps.com/blogs/deborahk/archive/2009/08/25/reading-fixed-length-files.aspx
Upvotes: 0
Reputation: 7591
take a look at http://www.filehelpers.com/ to export the data to a fixed file format. you may also want to look at http://hibernatingrhinos.com/open-source/rhino-etl to create a process that runs the export for you. rhino.etl includes operations for FileHelpers.
Upvotes: 1