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

FileHelpers.dll - Error Compiling Expression: Line 0: Metadata file '' could not be foun

I'm using FileHelpers.dll (v3.0.2.0) to parse a delimited file. It works fine on my development machine but on the dev server it fails on this LOC var cb = new DelimitedClassBuilder("Delimited", delimiter); // Do stuff, add fields, etc Type cls =…
0
votes
0 answers

Will the performance of AppendToFile(string,IEnumerable) slow down as the CSV file grows large?

I am using the AppendToFile method of DelimitedFileEngine from FileHelpers. Assumptions: Each row that I append is about 100 chars long. Moderate common PC hardware from the last 3 years, normal harddisk, 4GB ram. Frequency of calling…
Doochz
  • 1,039
  • 2
  • 14
  • 25
0
votes
1 answer

Filehelpers: parse fixed length file with different length of lines in

I've to parse a fixed length file containing multiple line but with different length. Actually each line represent a different kind of object that would be insert in the database. The file can be like…
fisdelom
  • 39
  • 3
  • 11
0
votes
1 answer

FileHelpers Library: AfterReadRecord Compilation Error

I'm hoping there's an expert in using the FileHelpers library here. I'm using the 2.9.9 stable version from Nuget and trying to use the AfterReadRecord event handler to test if fields are empty. The code I have is shown in simplified form…
Jake Howlett
  • 169
  • 3
  • 14
0
votes
2 answers

Zero filling null datetimes and formatting datetime

I'm trying to write a fixed length file with FileHelpers. A few of the fields I have are datetimes that can be null values. If they are null values I need them to be zero filled (i.e. "00000000" instead of the date). I tried using a custom field…
TOlsen
  • 45
  • 1
  • 2
  • 8
0
votes
0 answers

FileHelpers Read Int "NA"

I am trying to read in a CSV file using using FileHelpers (C#). I have an int column. However, when the file is invalid/missing it has "NA". In this case, I would like the behavior to be to have these retain the default value of 0. How do I…
0
votes
2 answers

FileHelpers - WriteStream Not Writing All The Data To Stream

I am writing an MVC application that will export data to a CSV file. I have some data pulled via a Linq query, and the query pulls all the correct records, but the data is not being completely written to the stream. I get partial or no data at all…
crimsonisland
  • 21
  • 1
  • 4
0
votes
0 answers

How to check a file is open or not in FileHelper

I am using FileHelper for exporting the data to csv for my C# project. I am facing an exception "The process cannot access the file" the reason is the file is already opened. Is there any option to check whether the file is already opened or…
Praveen
  • 55,303
  • 33
  • 133
  • 164
0
votes
1 answer

Linq to FileHelpers Class

I am trying to get the results of a linq query int a file. I created and array of the same type as the FileHelpers class I created, then queried the data and assigned the values to the array I just created. I get the following error: Object…
0
votes
1 answer

ErrorHandling in Filehelpers when using SqlStorage

I provided record containing column with integer type, instead of reporting errors (as documented here) got InvalidCastException in method below (for filling records in storage): protected void FillRecordOrder(object rec, object[] fields) { …
netdis
  • 321
  • 3
  • 12
0
votes
1 answer

hot to parse csv time in this format 06:00:00;00?

I have csv and reading it per line so I can save it in the DB. I am using filehelper to separate each by comma delimiter but ignore those that are inside "". It is throwing exception coz of the data 06:00:00;00. I am not sure what is that. How do I…
user742102
  • 1,335
  • 8
  • 32
  • 51
0
votes
1 answer

FileHelper reading csv file freezing

I am trying to use FileHelper to read a csv file, in which data are arranged like this: 0,0,0,0,0,0,0,1,1,1,0,0,0,0,...... 1kX1k of them. Here is my FileHelper code: [DelimitedRecord(",")] public class ROIMaskCSV { public int…
Nick Tsui
  • 524
  • 2
  • 9
  • 29
0
votes
1 answer

FileHelperEngine order of columns

hi i am using FileHelperEngine for parsing csv files. FileHelperEngine csvEngine = new FileHelperEngine(typeof (Model)); Model[] lines= csvEngine.ReadFile(fileName) as Model[]; this works fine if the columns order matchh the order of the properties…
dimka87il
  • 95
  • 6
0
votes
1 answer

Possible to get Value from Attribute?

I am using file helpers and I put on top of my class [DelimitedRecord("|")] I want to check though if the value is a "|" if not then I want to throw an exception.. public void WriteResults(IList resultsToWrite, string path, string fileName)…
chobo2
  • 83,322
  • 195
  • 530
  • 832
0
votes
1 answer

Using FileHelpers how do I pass individual data into variables?

Apologies in advance as I'm fairly new to this so imagine this is be being a fool. Anyway, I looking to pass individual comma delimited data into fields/variables. I am using FileHelpers and have it working and passing back data but my C# skills…
Woodman81
  • 53
  • 1
  • 7