Questions tagged [filehelpers]

FileHelpers is a .net utility library to help applications manage flat file input and output.

FileHelpers is a utility library to help .NET framework applications manage flat file input and output. The bulk of the library lives in an assembly with a number of "engine" classes that are used to drive I/O along with attributes that are used to decorate classes in your application.

Your code uses these attributes to define records:

namespace OBG.FileHelpers.Tests
{
    [FixedLengthRecord(FixedMode.ExactLength)]
    internal class FixedRec1
    {
        [FieldFixedLength(10)]
        [FieldAlign(AlignMode.Left)]
        [FieldNullValue("n/a")]
        [FieldTrim(TrimMode.Both)]
        public String String10Field1;

        [FieldFixedLength(10)]
        [FieldConverter(ConverterKind.Date)]
        public DateTime DateField2;

        [FieldFixedLength(12)]
        [FieldConverter(typeof(MoneyFieldConverter))]
        public decimal MoneyField3;
    }
}

To read or write files, then, one of the FileHelper engines works with the records you've defined to manipulate, format, and validate data:

var recs = new List<FixedRec1>();
recs.Add(new FixedRec1 { String10Field1 = "abc", DateField2 = DateTime.Today, MoneyField3 = 123.45M });

// Show truncation of field 1
recs.Add(new FixedRec1 { String10Field1 = "abcdefghijklmnopqrstuvwxyz", DateField2 = DateTime.Today, MoneyField3 = 123.45M });

// Show null translation of field 1
recs.Add(new FixedRec1 { DateField2 = DateTime.Today, MoneyField3 = 123.45M });

// Show illegal value for field3
recs.Add(new FixedRec1 { String10Field1 = "abc", DateField2 = DateTime.Today, MoneyField3 = -0.00001M });

// To write, use: 
engine.WriteFile("FileOut.txt", recs.ToArray());

You can extend FileHelpers by constructing your own custom attributes, such as converters to handle formats not natively provided by FileHelpers.

FileHelpers is open source software released under the MIT.

Roslyn Analyzer

Best practices and quick fixes for the library:

Image

References

454 questions
3
votes
1 answer

How to make a customer class for iteration fields Using FileHelper library

I'm using excellent FileHelpers library. I have a question for iteration fields of Customer class. As you can see below class, L1 ~ L51 is just field of datas. [DelimitedRecord(",")] public class Customer { public string Time; public double…
Changju.rhee
  • 463
  • 3
  • 11
  • 26
3
votes
4 answers

Exporting to CSV - C#

I need to export a generic list to CSV. Obviously I could write my own, but would like to avoid this! I am able to google and find a lot of CSV parsers, but not many writers. I have downloaded FileHelpers but it doesn't properly escape output. For…
anonymous
  • 6,825
  • 8
  • 47
  • 60
3
votes
1 answer

FileHelperEngine constructor - InvalidcastException

I'm trying to read a CSV file with FileHelpers (version 2.0.0 from the www.filehelpers.net site, I also tried Build 2.9.16 to no avail). my CSV class is as follows: [DelimitedRecord(";")] public class RawImportCandidate { public string Name1; …
Aether McLoud
  • 732
  • 1
  • 7
  • 20
3
votes
1 answer

Using FileHelpers to read CSV file from asp.net file upload

I'm working on an ASP.NET Webforms C# application. I need to have a CSV file uploaded to server and contents read and saved to database. I read somewhere that FileHelpers may be used for reading csv files but I haven't seen any example dealing with…
Moses Machua
  • 11,245
  • 3
  • 36
  • 50
3
votes
3 answers

FileHelpers writing a CSV with line breaks within the fields

Using FileHelpers, my C# application reads a CSV and then processes the data. After processing, the data is written as another CSV. The output CSV has got line breaks within some fields. How can those be avoided?
Vaishali Bulusu
  • 151
  • 2
  • 5
  • 10
3
votes
2 answers

asp.net filehelpers write file to client directly

I'm using the FileHelpers library for a C# .net project. All is working ok except I need to have the generated CSV savable via a button click. So the user clicks a button and they get a prompt to save the file. I know Filehelpers has a WriteStream…
Full Time Skeleton
  • 1,680
  • 1
  • 22
  • 39
3
votes
3 answers

How do I read only a set number of fields from a csv using the FileHelpers library?

I've got an application on my hands that uses the FileHelpers library to process csv files. In the past, the input csv files always had the same structure, 5 comma-separated fields for a record, then a new line to delimit records. Recently,…
sdds
  • 2,021
  • 2
  • 25
  • 33
3
votes
1 answer

Filehelpers datalink to connect to Oracle DB

http://filehelpers.sourceforge.net/example_sqlstorage_extract.html The example above connects to SQl server. My requirement is to connect to Oracle DB.I found no class in filehelpers which i can use to connect to oracle DB. Please help if you have…
user1046415
  • 779
  • 4
  • 23
  • 43
3
votes
1 answer

I added `Marcos Melis Filehelpers` via Nuget and I am getting a warning which I don't understand, what does it mean?

Basically I added Marcos Meli's FileHelpers to my Visual Studio Project and I am getting the following warning: A reference was created to embedded interop assembly 'x:\y\packages\FileHelpers.2.0.0.0\lib\Interop.Excel.dll' because of an indirect…
JMK
  • 27,273
  • 52
  • 163
  • 280
3
votes
4 answers

How do I setup filehelpers with a required, not empty column

I've been looking through filehelpers documentation, but there doesn't seem anything to handle empty values in columns. I need to be able to set a 'non-empty' string attribute on all the columns. Can anyone point me in the right direction?
jaffa
  • 26,770
  • 50
  • 178
  • 289
2
votes
2 answers

How do you do custom validation on FileHelpers?

I want to throw an exception to say that we have an invalid email address as I dont want to proceed until we get a valid email address. Is this where I want to do it and if so, how? void Engine_AfterReadRecord(EngineBase engine,…
Ronnel
  • 656
  • 7
  • 9
2
votes
3 answers

Using FileHelpers; how to parse this CSV type

Having a few problems trying to parse a CSV in the following format using the FileHelpers library. It's confusing me slightly because the field delimiter appears to be a space, but the fields themselves are sometimes quoted with quotation marks, and…
Richard
  • 1,252
  • 12
  • 23
2
votes
2 answers

Multiple CSV structures with FileHelpers

I am making a site that consumes a csv file this file can come in 2 formats(maybe more in the future). Structure 1 Header 1 Header 2 Header 3 Header 4 a b c d x x x x Structure 2 Header 1 Header 4 a …
chobo2
  • 83,322
  • 195
  • 530
  • 832
2
votes
6 answers

How to use a dynamic CSV delimiter with FileHelpers?

Question: I need to read a CSV file. I use the FileHelpers library to achieve this. The problem is I need a dynamic delimiter (user defined), meaning anything can be delimiter (Comma, semicolon, tab, newline, but also anything else). The problem…
Stefan Steiger
  • 78,642
  • 66
  • 377
  • 442
2
votes
3 answers

FileHelpers change RecordLine before reading the record

I am reading a huge file using FileHelpers library. I would like to change the RecordLine before reading the record like below. static void engine_BeforeReadRecord(object sender, BeforeReadRecordEventArgs e) { if…
Rajan R.G
  • 825
  • 1
  • 7
  • 10