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
0
votes
2 answers

Removing the optional fields from writing to text field Filehelpers

How do I go about removing the optional field from the text field that I have output using the Filehelpers library. I'm using c# For example, I have a shared class file with attributes such as recordnumber, filler, payment, endingspaces Then I need…
0
votes
2 answers

Multi delimiter on the same row

I would use FileHelpers to import a file like this, STATUS,USERID,CUSTOM1,CUSTOM2 Active,000001,"Company division "A"", "HRO" Active,000002,"Company HQ", "HRO" but I can not find how to specify a field delimiter which in turn may contain the…
DaniloZ
  • 49
  • 4
0
votes
2 answers

Using File-Helper to handle extra comma in record CSV parser

I am trying to process a LLarge CSV file - 1Gb where sometimes I may get records where column value has ',' in…
sandeeMPS
  • 217
  • 3
  • 12
0
votes
1 answer

FileHelpers: The delimiter '|' can´t be found after the field

I have huge CSV file (1GB) which looks like…
codelikeprogrammerwoman
  • 1,429
  • 3
  • 14
  • 17
0
votes
0 answers

Intermittent FileHelpers constructor NullReferenceException

I've suddenly started getting intermittent NRE's with the following stack: at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at FileHelpers.RecordInfo.RecordInfoFactory.Resolve(Type type) at…
sming
  • 801
  • 2
  • 12
  • 25
0
votes
1 answer

C# FileHelpers Excluding Fields From Write

I am using Filehelpers to export a collection of a class to a csv file. The class is used to store user info and has 5 fields, i want to export different fields in different circumstances. so the collection will either be all new users where i only…
R Davies
  • 105
  • 1
  • 11
0
votes
1 answer

Importing a multiline record with optional fields using filehelpers

I'm in the process of needing to parse a file who's records are of the following format: mr Sean r. Farrow 4 The Crescent Eastleake Loughborough Leicestershire LE12 6QH 01509 59213 07525945447 sean.farrow@seanfarrow.co.uk Each record is delimited…
Sean Farrow
  • 69
  • 1
  • 3
0
votes
1 answer

FileHelpers library ignoreFirstLine issue

I have a CSV file which I am trying to import using file Helpers Library, issue is I get the spree sheet files from somewhere and save them as CSV to be able to import them but the first line has Wrap-text excel properties which make the cell into…
DisplayName
  • 71
  • 1
  • 7
0
votes
1 answer

Looking for FileHelpers Master Detail Direction

I have a .csv file that comes in this format. I'm using the FileHelpers library but I need some direction on parsing the file into a single record so the collection can be inserted into a database. At this point I believe the "Total" line can be…
Tim
  • 1,249
  • 5
  • 28
  • 54
0
votes
1 answer

Filehelpers import datetime to sql

I'm using Filehelpers and I'm trying to import a CSV file that contains two Datetime fields (ddMMyyy hh:mm) that I can't upload to my table. I tried this : public class TBAtable { public string BookingNum; public string…
Hind Ahmamad
  • 51
  • 1
  • 1
  • 5
0
votes
2 answers

Field Attributes on base class are used in Derived Class when reading

I'm trying to use polymorphism correctly to avoid a ton of extra code, but the file engine appears to throw errors as if it were using the base class instead of the derived class. Ideal situation: create a read base class user uploads a file, and…
Paul42
  • 194
  • 1
  • 11
0
votes
0 answers

FileHelpers tab “\t” delimited reader issue

I'm pretty new to this but i am not really sure why this isn't working. I have a tab delimited file i am trying to import using vb.Net and FileHelpers.dll Imports System Imports System.Collections.Generic Imports System.Text Imports FileHelpers…
0
votes
2 answers

FileHelper ReadFile() returns null

I'm working with the great FileHelpers library (version 2.9.9). However I've been stuck for some hours now and I'm not able to work this issue out. I would like to load my file into an array of my CustomerClass object. I would like to change the…
jmelhus
  • 1,130
  • 2
  • 12
  • 28
0
votes
1 answer

Filehelpers - Complex record layout assistance

We are attempting to use filehelpers for some file interface projects specifically dealing with EDI. The sample definition below makes use of the EDI 858 Specification. Like most interface specs, each vendor has their own flavor. You can find a…
ecathell
  • 1,030
  • 13
  • 25
0
votes
1 answer

Write to String using the FixedLengthClassBuilder

I have a c# class called "SepaRecord", already defined in a dll which I cannot modify. I have a List at runtime which I need to convert into a fixed length file. The approach which I have tried is, using the FixedLengthClassBuilder I create a…
chrisl08
  • 1,658
  • 1
  • 15
  • 24