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 Library - AfterReadRecord exceptions not being caught

I'm using the FileHelpers library, version 2.9.9 from NuGet. I'm running into a problem while trying to use the AfterReadRecord event. When I throw an exception from this event, the exception is not caught by the library. It's my understanding that…
nivek
  • 3
  • 2
0
votes
1 answer

Filehelpers Quoted Tab-Separated-Values error

I am getting an error using Quoted, Tab-Delimited input. The same input with no Quotes works perfectly. Here is a sample input line with '!' denoting a TAB character: CN!"000012"!"Contents page 1 of 000012" Here is the error message: Line: 1…
litespeed
  • 11
  • 4
0
votes
1 answer

Trim characters while using FileHelpers

I am using FileHelpers to parse csv file and to load it in a datatable. I am using xml template and pass it to ClassBuilder.LoadFromXml I want certain characters to be trimmed from a particular field and I think there is something we can mention in…
Jigar Sheth
  • 586
  • 2
  • 5
  • 21
0
votes
1 answer

How to add header using Filehelper with DataTableToCSV

I am using: DataTableToCSV(datatable,filepath) to create a CSV file. Which is generating perfect CSV. Now how do I add column names when using DataTableToCSV?
Rizwan Mumtaz
  • 3,875
  • 2
  • 30
  • 31
0
votes
1 answer

FileHelpers trimming last character of value

var columnNames = new string[] {"A","B","C"}; var cb = new DelimitedClassBuilder("GeneratedClassName", ",") { IgnoreFirstLines = 0, IgnoreEmptyLines = true, Delimiter = "," }; foreach (var header in columnNames) { …
Abhijeet Nagre
  • 876
  • 1
  • 11
  • 21
0
votes
1 answer

When extracting records from a database using Filehelpers, how do I handle binary fields?

I am using Filehelpers to read data from a database. I have based my code on the example in: http://filehelpers.sourceforge.net/example_sqlstorage_extract.html My question is, given my code here, how do I handle binary fields? public class…
Armand Jordaan
  • 348
  • 2
  • 11
0
votes
1 answer

FileHelpers Master/Detail - Option Strict On disallows late binding

I am having some problems to determine how can i remove the errors i am having using FileHelpers with the option strict on. I initialized the class MasterDetails Private _res As MasterDetails() The function to call the MasterDetailEngine Private…
Filipe Costa
  • 655
  • 3
  • 13
  • 30
0
votes
4 answers

Is it possible to add a $ to a field using FileHelpers library

Is it possible to add a $ to a field using FileHelpers library? I have an object [DelimitedRecord("|")] public class TradesToBloombergFileHeaders { [FieldOrder(1)] public Guid id; [FieldOrder(2)] public string name; …
Boroda
  • 195
  • 1
  • 7
  • 23
0
votes
1 answer

Testing error handling when writing a csv file

I would like to set ErrorMode = ErrorMode.SaveAndContinue so I can process errors after a CSV file has been written. How can I generate row level errors artificially when calling WriteStream() so that I can test my error handling? In particular I…
Ian Warburton
  • 15,170
  • 23
  • 107
  • 189
0
votes
1 answer

FileHelpers import issues

Good afternoon, i've been trying to import a field from a txt/csv file and it keeps causing an error in my import. I know why i just can't seem to figure out how to resolve it. I have a string filed listed below that is causing an error when it…
0
votes
1 answer

Filehelpers add footer to generated excel file

I am using Filehelpers to write excel file. It has property TemplateFileso i can use file as template for rows. But how can I add footer there? I want to add summary there. Is there any way of doing that?
Sreginogemoh
  • 1,309
  • 3
  • 10
  • 12
0
votes
1 answer

Filehelpers ExcelStorage read template from resources

Filehelpers ExcelStorage has a property public string TemplateFile { get; set; } For that reason I have to keep my template file in the program directory (bin). But if I want to use my template file as a embedded resource is there any way I can…
Sreginogemoh
  • 1,309
  • 3
  • 10
  • 12
0
votes
3 answers

error when using filehelpers on IIS; sometimes :S : [PolicyException: Required permissions cannot be acquired.]

FileHelpers.dll (2.0) are referenced within 2 class libraryies (Dto and Services) in my solution My webapp (asp.net mvc) is on IIS7 (Full Trust) Windows 7 PRO 64 and I sometimes get this exception when starting my app from VS2008: (to get rid of it…
Omu
  • 69,856
  • 92
  • 277
  • 407
0
votes
1 answer

How to get notified in the progress of the operations in ExcelStorage of FileHelpers

Documentation http://www.filehelpers.com/example_progress.html saying that i need to use method SetProgressHandler but ExcelStorage does not have it. ExcelStorage has method public event EventHandler Progress; so looks like i…
Sreginogemoh
  • 1,309
  • 3
  • 10
  • 12
0
votes
2 answers

HttpResponse truncating output

FileHelperEngine engine = new FileHelperEngine(typeof(OrderCsvRow)); var writer = new StreamWriter(Response.OutputStream); engine.WriteStream(writer, someOrders); When I output the orders as a string it comes out fine. when I use…
Ian Warburton
  • 15,170
  • 23
  • 107
  • 189