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
-2
votes
1 answer

What's the "best practice" for when to create a FileHelpers engine?

I have a class in a Windows Forms application that is processing at peak 10 - 20 records per minute, but at non-peak it might go two or three hours without doing anything. As I see it, you can structure the FileHelpers engine lifecycle two…
Walt
  • 312
  • 3
  • 7
-2
votes
1 answer

Deserializing csv with unknown headers to a List or Array

My question is different from other SO questions, because those deserialization samples are for a typed POCO class, in my scenario I don't have any types ahead of time. Files are being dropped in a folder from various sources. Without, the…
Transformer
  • 6,963
  • 2
  • 26
  • 52
-2
votes
1 answer

FileHelpers, how to separate text in multiple classes using only one line , identified by keys?

I have a text that is more or less like this: I10JOAO OF SILVAI202210I30 ... where : I10 is a key to the Person class I20 is a key to another class so on ... How to proceed using the FileHelpers library?
-2
votes
1 answer

How to partition a file in Filehelpers

I'm trying to partition a file in 12.000 lines, using Filehelpers (3.0.39.0). Below follows my code: 'Busca informações do Discador Dim dtDiscadores As New DataTable mensagemErro +=…
cfasilva
  • 3
  • 4
1 2 3
30
31