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

439 questions
0
votes
1 answer

FileHelper library - custom error messages

I am use the FileHelper to parse CSV files. Error messages encountered when parsing the file are displayed to the end user. The end user may not be able to make sense of the technical error message. Not too many clerks know what an Int32 is or…
Jason Meckley
  • 7,529
  • 1
  • 22
  • 44
0
votes
1 answer

FileHelpers: FieldNotInFile attribute completely omits field from ReadFileAsDT DataTable results

I'm running into what appears to be unexpected behavior when utilizing the FieldNotInFile attribute in my mapping file. Please see below, abbreviated examples of what I have configured. The mapping for the header record is defined separately to…
NickSuperb
  • 1,134
  • 1
  • 8
  • 27
0
votes
1 answer

Parse flat file with multiple formats

Its been a while since Ive had to write what amounts to a custom format edi processor. The last time I wrote one, I was an AS/400 programmer (not iSeries to give you a timeframe). It was pretty easy, I built a structure and inspected the record…
jason
  • 747
  • 2
  • 9
  • 24
0
votes
1 answer

FileHelpers file access

I am trying to get my head over FileHelpers library and have main critical problem. When I try to implement it in my web app, or even use online demo I end up with "FileNotFoundException". The chosen file is being looked for on my C: drive. How can…
Bartosz
  • 4,192
  • 9
  • 40
  • 66
0
votes
1 answer

CSV File Helper : Line is empty error - how to add attribute [IgnoreEmptyLines] in record class

i m constantly getting error while using Csv Parser ( File helper ) . it asking some attribute set for to avoid empty. but i am totally clue less what to do . how to set "IgnoreEmptyLines" in class ? my sample csv file is and this is server…
panindra
  • 626
  • 2
  • 11
  • 31
0
votes
2 answers

File helpers to read data from sql

I recently started using filehelpers. FileHelperEngine engine = new FileHelperEngine(typeof(Customer)); Customer[] customers = (Customer[]) engine.ReadFile(@"..\Data\CustomersDelimited.txt"); Instead of reading data from a file,I have to read data…
user1046415
  • 739
  • 3
  • 19
  • 42
0
votes
1 answer

How to read two entities from single text file using filehelpers or other library in C#

Text file contains order and order detail lines. First line in order header. After that there is variable number of detail lines. After detail there is blank line followed by next order etc. For order line first field is order number. For detail…
Andrus
  • 22,189
  • 50
  • 171
  • 330
0
votes
3 answers

FileHelpers cannot map converted field into destination array

I have the following record (reduced for brevity): [DelimitedRecord(",")] [IgnoreFirst] [IgnoreEmptyLines()] public class ImportRecord { [FieldQuoted] [FieldTrim(TrimMode.Both)] public string FirstName; …
jaffa
  • 24,659
  • 47
  • 173
  • 282
-1
votes
3 answers

Filehelpers some columns are not written

I am writing this class to a file. But for some reason, some of the rows have some columns missing. By this, I mean that some columns are shifted a few times to the left. I can see this on the last column, because it should have a "true" in all…
Theodor349
  • 71
  • 1
  • 10
-1
votes
1 answer

C# importing csv file into SQL database using FileHelpers

i'm trying to import a .csv file using the great FileHelpers library. Doing some research most of the time i read that i should use BulkCopy to import the result into an SQL database table. Could you please help me how to accomplish this? So far i…
BrianF.
  • 3
  • 4
-1
votes
1 answer

How to detect Column datatype at runtime, while parsing a CSV file with header

I am using FileHelpers to load CSV data, (credit - while searching found this answer/search result). The user browses a dir., selects the files with headers, and uploads for parsing. My issues is that -- they are one time files, whose…
Transformer
  • 3,100
  • 17
  • 40
-1
votes
2 answers

uploading multiple csv files to SQL server in c#

My problem was solved. I took down my code for privacy reasons
Brandon t
  • 33
  • 8
-1
votes
1 answer

FileHelpers.Dynamic.ClassBuilder.CreateRecordClass Error

I'm trying to reading a file with layout created at runtime. But when running FixedLengthClassBuilder.CreateRecordClass (), an exception occurs: Error Compiling Expression: Line 31: The type or namespace name 'SGCompras' could not be found (are you…
-1
votes
1 answer

FileHelpers : Record has more fields than expected

I am using FileHelpers libary and I have a pipe "|" delimited file that must have only 4 fields, and I need to validate when a record has more than 4 fields and save error. bla|bla2|bla3|bla4 <- Good Record bla|bla2|bla3|bla4|bla5 <- Wrong…
-1
votes
1 answer

Cannot convert method group to string error

A little green when it comes to C# so I would really appreciate some help on this. I keep getting this error on this part of my code. Error 1 The best overloaded method match for 'FileHelpers.FileHelperEngine.ReadString(string)' has some…
traci
  • 1
  • 4
1 2 3
29
30