filehelpers

Design pattern for grouping fields and structuring data in a flat file

泄露秘密 提交于 2019-12-11 04:55:46
问题 I am using the FileHelpers C# library to read a file into an array of custom objects that will be processed. For instance, a partial file definition: [FixedLengthRecord] public class Row { [FieldFixedLength(9)] [FieldTrim(TrimMode.Right)] public string Ssn; [FieldFixedLength(15)] [FieldTrim(TrimMode.Right)] public string LastName; ... } I'm trying to abide by OOP principles while doing this and I've noticed that some fields have a natural grouping (e.g. SSN and ClientID , EmployerID and

FileHelpers: How to handle quoted fields when reading file

你离开我真会死。 提交于 2019-12-11 03:30:57
问题 Here's the data I want to read: "Adam C. Emality","1Z620Y1V034826","14.40" "Ethel Baeron","1Z620Y1V034604","15.19" "Donna Lidt","1Z620Y1V034650","12.37" Then after reading the data in, I want to perform a Join on the two collections, one an array and one a list - my code below. However after executing the read file line my strings are stored like this "\"Adam C. Emality\"" "\"1Z620Y1V034826\"" "\"14.40\"" ...etc.. Why is this happening? I do not want to include the " and I don't know why it

Order of fields in a type for FileHelpers

帅比萌擦擦* 提交于 2019-12-10 22:25:20
问题 I'm reading a simple CSV file with Filehelpers - the file is just a key, value pair. (string, int64) The f# type I've written for this is: type MapVal (key:string, value:int64) = new()= MapVal("",0L) member x.Key = key member x.Value = value I'm missing something elementary here, but FileHelpers always assumes the order of fields to be the reverse of what I've specified - as in Value, Key. let dfe = new DelimitedFileEngine(typeof<MapVal>) let recs = dfe.ReadFile(@"D:\e.dat") recs |> Seq

asp.net filehelpers write file to client directly

邮差的信 提交于 2019-12-10 21:20:10
问题 I'm using the FileHelpers library for a C# .net project. All is working ok except I need to have the generated CSV savable via a button click. So the user clicks a button and they get a prompt to save the file. I know Filehelpers has a WriteStream option but their own documentation shows only an example of WriteFile. I don't know if WriteStream is what's needed but I think it is. Anyone know if it's possible to have the CSV file saved directly to the client rather than to the server hard

How to define a default value for a field of a FileHelpers element class

怎甘沉沦 提交于 2019-12-10 14:00:04
问题 I'm trying to load a CSV file (delims are ';' and quotes are '"'). I have successfully created everything (the wizard tool is awesome), but there's one thing that I can't find a solution for. Basically, I have an integer (System.Int32) column. In theory most of the records will have a positive integer value in that column. Sometimes, however, I might encounter a value "N/A" in that column. What I want to achieve, is have FileHelpers assign a default value (-1 works just fine), when it

Using FileHelpers without a type

拈花ヽ惹草 提交于 2019-12-10 13:19:06
问题 I have a CSV file that is being exported from another system whereby the column orders and definitions may change. I have found that FileHelpers is perfect for reading csv files, but it seems you cannot use it unless you know the ordering of the columns before compiling the application. I want to know if its at all possible to use FileHelpers in a non-typed way. Currently I am using it to read the file but then everything else I am doing by hand, so I have a class: [DelimitedRecord(",")]

Dynamically create a CSV file with FileHelpers

我们两清 提交于 2019-12-08 19:32:19
问题 FileHelpers supports a feature called "RunTime Records" which lets you read a CSV file into a DataTable when you don't know the layout until runtime. Is it possible to use FileHelpers to create a CSV file at runtime in the same manner? Based on some user input, the CSV file that must be created will have different fields that can only be known at runtime. I can create the needed Type for the FileHelper engine as described in their reading section, but I can't figure out what format my data

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

风流意气都作罢 提交于 2019-12-08 14:09:28
问题 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 cols/classes/types are not known previously . Question : how can I detect the column's datatype while parsing? After searching I found a function called public Type RecordType { get; } it provides the record type.. I need help to get the Col data type in the

Ignoring last lines in CSV using Filehelpers if they aren't input

大憨熊 提交于 2019-12-08 08:35:06
问题 I built a program using FileHelpers to parse CSV files and it works wonders, except I'm running into an issue. Some of the files - but not all - have a number of extra lines in the end with information that does not pertain to actual fields. like so ... 31,4104019, ,,1043,,,0,,Ventas Total Credito,1,1,277.98,0,0,0,0,21.5040000000,V, 31, ,11212302,,1043,,,0,,Ventas Total Credito,1,1,33.28,0,0,0,0,21.5040000000,V, 31, ,11212307,,1043,,,0,,Ventas Total Credito,1,1,277.98,0,0,0,0,21.5040000000,V,

Handling NEWLINE in DelimitedRecord with Filehelpers

旧巷老猫 提交于 2019-12-07 10:24:58
问题 Am using the excellent FileHelpers library to parse a number of different files. One of these files has (some) lines that look like this id|name|comments|date 01|edov|bla bla bla bla|2012-01-01 02|john|bla bla bla bla|2012-01-02 03|Pete|bla bla <NEWLINE> bla bla|2012-03-01 04|Mary|bla bla bla bla|2012-01-01 Note that line with id 3 has a newline in the text. Also note the comments are not surrounded by quotes so [FieldQuoted('"', MultilineMode.AllowForRead)] isn't going to save me.