filehelpers

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

假如想象 提交于 2019-12-01 23:41:06
This question already has an answer here: Getting the attributes of a field using reflection in C# 1 answer 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 the custom attribute value inside the set method of the property. How do I achieve this? MSTdev You can do this using reflection

ReadStreamAsDT - Filehelpers and C# - How do I dynamically read in a CSV using filehelpers?

こ雲淡風輕ζ 提交于 2019-12-01 10:19:23
问题 I am attempting to read in a CSV dynamically via FileHelpers and work with the CSV data as a datatable. My CSV files will not be the same. They will have different column headers and different amounts of columns. I am using the ReadStreamAsDT method, but it seems to still want a structured class to initialize the FileHelperEngine. Any ideas? 回答1: I had to use FileHelpers.RunTime and the DelimitedClassBuilder to create a DataTable from the file. Here is my method. If I get more time, I will

ReadStreamAsDT - Filehelpers and C# - How do I dynamically read in a CSV using filehelpers?

随声附和 提交于 2019-12-01 10:11:21
I am attempting to read in a CSV dynamically via FileHelpers and work with the CSV data as a datatable. My CSV files will not be the same. They will have different column headers and different amounts of columns. I am using the ReadStreamAsDT method, but it seems to still want a structured class to initialize the FileHelperEngine. Any ideas? I had to use FileHelpers.RunTime and the DelimitedClassBuilder to create a DataTable from the file. Here is my method. If I get more time, I will explain this better. private static DataTable CreateDataTableFromFile(byte[] importFile) { var cb = new

FileHelpers and CSV: what to do when a record can expand unbounded, horizontally

旧时模样 提交于 2019-11-30 13:00:25
I'm trying to parse this type of CSV file with FileHelpers: Tom,1,2,3,4,5,6,7,8,9,10 Steve,1,2,3 Bob,1,2,3,4,5,6 Cthulhu,1,2,3,4,5 Greg,1,2,3,4,5,6,7,8,9,10,11,12,13,14 I can't figure out how to parse this with FileHelpers. I would imagine I should be able to do something like this: [DelimitedRecord(",")] public class MyRecord { public string Name; public List<int> Values; } But that doesn't appear to be possible with FileHelpers. The best I can seem to do is this: [DelimitedRecord(",")] public class MyRecord { public string Name; public string Values; public string[] ActualValuesInNiceArray {

Column headers in CSV using fileHelpers library?

ぐ巨炮叔叔 提交于 2019-11-29 20:34:43
Is there a built-in field attribute in the FileHelper library which will add a header row in the final generated CSV? I have Googled and didn't find much info on it. Currently I have this: DelimitedFileEngine _engine = new DelimitedFileEngine(T); _engine.WriteStream (HttpContext.Current.Response.Output, dataSource, int.MaxValue); It works, but without a header. I'm thinking of having an attribute like FieldTitleAttribute and using this as a column header. So, my question is at which point do I check the attribute and insert header columns? Has anyone done something similar before? I would like

FileHelpers and CSV: what to do when a record can expand unbounded, horizontally

怎甘沉沦 提交于 2019-11-29 18:45:40
问题 I'm trying to parse this type of CSV file with FileHelpers: Tom,1,2,3,4,5,6,7,8,9,10 Steve,1,2,3 Bob,1,2,3,4,5,6 Cthulhu,1,2,3,4,5 Greg,1,2,3,4,5,6,7,8,9,10,11,12,13,14 I can't figure out how to parse this with FileHelpers. I would imagine I should be able to do something like this: [DelimitedRecord(",")] public class MyRecord { public string Name; public List<int> Values; } But that doesn't appear to be possible with FileHelpers. The best I can seem to do is this: [DelimitedRecord(",")]

Getting FileHelpers 2.0 to handle CSV files with excess commas

佐手、 提交于 2019-11-29 11:11:58
I am currently using the FileHelpers library (v2.0.0.0) to parse a CSV file. The CSV file is mapped to a class that has a handful of public properties, let's say there are N . The problem is that, by default, FileHelpers doesn't seem to correctly handle cases where the user specifies a CSV file that has more than N-1 commas. The remaining commas just get appended to the last property value. I figured this must be configurable via FileHelpers' attributes , but I didn't see anything that would ignore fields that don't have a matching property in the record. I looked into the RecordCondition s,

FileHelper escape delimiter

浪子不回头ぞ 提交于 2019-11-29 10:56:01
I am using FileHelper 2.0 for parsing my csv data. Is there any option that filehelper can properly handle escaped delimiter? That it can identify field as data and not as delimiter. Our csv format: escape comma (,) with \, Example data: name, lastname nico\,le,opeka Current code: [DelimitedRecord(",")] public class contactTemplate { public string firstName; public string lastName; } How can I get firstName = nico,le and lastName = opeka. FileHelpers splits by comma , and now it returns: firstName -> nico\ lastName -> ,le,opeka shamp00 First, you need to make all of your fields optionally

FileHelpers throws OutOfMemoryException when parsing large csv file

时光总嘲笑我的痴心妄想 提交于 2019-11-29 07:49:10
I'm trying to parse a very large csv file with FileHelpers ( http://www.filehelpers.net/ ). The file is 1GB zipped and about 20GB unzipped. string fileName = @"c:\myfile.csv.gz"; using (var fileStream = File.OpenRead(fileName)) { using (GZipStream gzipStream = new GZipStream(fileStream, CompressionMode.Decompress, false)) { using (TextReader textReader = new StreamReader(gzipStream)) { var engine = new FileHelperEngine<CSVItem>(); CSVItem[] items = engine.ReadStream(textReader); } } } FileHelpers then throws an OutOfMemoryException. Test failed: Exception of type 'System.OutOfMemoryException'

Column headers in CSV using fileHelpers library?

孤街浪徒 提交于 2019-11-28 16:37:47
问题 Is there a built-in field attribute in the FileHelper library which will add a header row in the final generated CSV? I have Googled and didn't find much info on it. Currently I have this: DelimitedFileEngine _engine = new DelimitedFileEngine(T); _engine.WriteStream (HttpContext.Current.Response.Output, dataSource, int.MaxValue); It works, but without a header. I'm thinking of having an attribute like FieldTitleAttribute and using this as a column header. So, my question is at which point do