filehelpers

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

落花浮王杯 提交于 2019-12-07 08:09:26
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, ;Importado="01/11/2013" //blank line here too I know FileHelpers has the [IgnoreLast(3)] public class

Formatting properties with FileHelper

。_饼干妹妹 提交于 2019-12-06 03:17:17
问题 FileHelpers has a nice date converter for fields: [FieldConverter(ConverterKind.Date, "MM-dd-yyyy")] public DateTime MyDate; FieldConverter does not work with properties though. I have to deal with objects that use properties so I was looking for something like this: [PropertyConverter(ConverterKind.Date, "MM-dd-yyyy")] public DateTime MyDate { get; set; } How do I do this with properties? 回答1: You cannot use converters with Properties. However, what you can do is create a data model just for

FileHelpers: Optional fields in non-quoted CSV

喜你入骨 提交于 2019-12-05 13:10:30
I am using FileHelpers to import data from a CSV file. Problem is, some versions of the CSV file have more fields than others. As such, I have marked the fields that are sometimes missing as being optional, but this does not seem to work as instead of just ignoring when fields are missing (which it seems to do ok) it is also always chopping the last character off of the last field that is present. For example... a row containing "ABC,DEF,GHI" (without the quotes) imports as "ABC", "DEF" & "GHI" a row containing "ABC,DEF" (again without the quotes) imports as "ABC" & "DE" My record format is

FieldConverter ConverterKind.Date “dd/MM/yyyy” exception

元气小坏坏 提交于 2019-12-05 11:00:14
I try to read a csv file. my fifth record contans a date: 03/11/2008 This is a piece of my code: [FieldConverter(ConverterKind.Date, "dd/MM/yyyy")] public DateTime datum_5; My code crashs on this: Result[] results= (Result[])engine.ReadFile(@"..\Data\expo.txt"); And with this exception: Line: 1. Column: 41. Field: datum_5. Error Converting '03/11/2008' to type: 'DateTime'. Using the format: 'dd/MM/yyyy' When i do this: [FieldConverter(typeof(ConvertDate))] public DateTime datum_5; with this: internal class ConvertDate : ConverterBase { /// <summary> /// different forms for date separator : .

Getting values from Custom Field Attributes in C#

 ̄綄美尐妖づ 提交于 2019-12-04 14:50:23
This morning I embarked on what I thought would be a quick exercise to use custom field attributes. Having tried many things and searching many examples (most involving class rather than field attributes), I'm officially stuck. My code is below. One peculiarity is that the class is built in FileHelpers using the classbuilder. My various partially successful attempts did manage to get the fieldnames from this class though, so I believe that part works fine. What I want to do (per the comment in the code) is a) Run through the fields, b) for each, see if the DBDataTypeAttribute Attribute exists,

How to export large SQL Server table into a CSV file using the FileHelpers library?

百般思念 提交于 2019-12-04 10:38:32
问题 I'm looking to export a large SQL Server table into a CSV file using C# and the FileHelpers library. I could consider C# and bcp as well, but I thought FileHelpers would be more flexible than bcp. Speed is not a special requirement. OutOfMemoryException is thrown on the storage.ExtractRecords() when the below code is run (some less essential code has been omitted): SqlServerStorage storage = new SqlServerStorage(typeof(Order)); storage.ServerName = "SqlServer"; storage.DatabaseName =

Can the FileHelpers library write classes containing nullable fields as well as read them?

白昼怎懂夜的黑 提交于 2019-12-04 08:01:44
I'm using version 2.0 of the FileHelpers library which is documented as being able to handle .NET 2.0 Nullable types. I'm using the code given in the example from the documentation: [DelimitedRecord("|")] public class Orders { public int OrderID; public DateTime? OrderDate; [FieldConverter(ConverterKind.Date, "ddMMyyyy")] public DateTime? RequiredDate; public int? ShipVia; } With a FileHelperEngine I can successfully read in a file which has no value for the OrderDate, RequiredDate or ShipVia fields. The file looks like: 1||| However, I cannot then write out the resulting Orders[] to file -

How do I get the custom attribute value of a field? [duplicate]

独自空忆成欢 提交于 2019-12-04 04:43:11
问题 This question already has an answer here : Getting the attributes of a field using reflection in C# (1 answer) Closed 6 years ago . I am using FileHelpers to write out fixed length files. public class MyFileLayout { [FieldFixedLength(2)] private string prefix; [FieldFixedLength(12)] private string customerName; public string CustomerName { set { this.customerName= value; **Here I require to get the customerName's FieldFixedLength attribute value** } } } As shown above, I would like a access

FileHelpers: How to skip first and last line reading fixed width text

纵然是瞬间 提交于 2019-12-03 23:07:41
Code below is used to read fixed width uploaded file content text file using FileHelpers in ASP .NET MVC2 First and last line lengths are smaller and ReadStream causes exception due to this. All other lines have proper fixed width. How to skipt first and last lines or other way to read data without exception ? [FixedLengthRecord()] class Bank { [FieldFixedLength(4)] public string AINETUNNUS; [FieldFixedLength(16)] public string TEKST1; [FieldFixedLength(3)] public string opliik; [FieldFixedLength(2)] public string hinnalis; }; [AcceptVerbs(HttpVerbs.Post)] [Authorize] public ActionResult

How to export large SQL Server table into a CSV file using the FileHelpers library?

安稳与你 提交于 2019-12-03 06:26:29
I'm looking to export a large SQL Server table into a CSV file using C# and the FileHelpers library. I could consider C# and bcp as well, but I thought FileHelpers would be more flexible than bcp. Speed is not a special requirement. OutOfMemoryException is thrown on the storage.ExtractRecords() when the below code is run (some less essential code has been omitted): SqlServerStorage storage = new SqlServerStorage(typeof(Order)); storage.ServerName = "SqlServer"; storage.DatabaseName = "SqlDataBase"; storage.SelectSql = "select * from Orders"; storage.FillRecordCallback = new FillRecordHandler