filehelpers

Skipping a column in FileHelper

喜你入骨 提交于 2019-12-13 13:02:19
问题 Using the FileHelper library for .Net, can I somehow skip a number of columns from the source file? According to docs and samples, I have to add fields for all columns. Alas, I have an excel sheet with 216 columns to import, from which as few as 13 are necessary. 回答1: I have the same situation, and question. Searching the forums at filehelpers.net, I found this thread (from 2007?!) with a response by Marcos himself: Question: In a delimited length layout, is it possible to skip some fields?

filehelpers - Parsing variable line length

戏子无情 提交于 2019-12-13 01:34:04
问题 I have to parse (C#) a .CSV file, with a variable "width" and 2 lines of header information (the fist one being name and the second one being the unit). The data looks like: Example1.CSV: "timestamp","NAME_1","NAME_2","NAME_3","NAME_4" "ms","unit_1","unit_2","unit_3","unit_4" 0.01,1.23,4.56,7.89,0.12 0.02,1.23,4.66,7.89,0.11 0.03,1.23,4.76,7.89,0.11 0.04,56.23,4.86,7.89,0.12 Example2.CSV: "timestamp","NAME_1","NAME_2","NAME_3","NAME_4","NAME_5",...,"NAME_N" "ms","unit_1","unit_2","unit_3",

Getting values from Custom Field Attributes in C#

廉价感情. 提交于 2019-12-12 08:58:38
问题 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

Filehelper differenciate errors based on Exception Message and manipulate record string

*爱你&永不变心* 提交于 2019-12-12 05:09:26
问题 I am using the FileHelpers library for identifying errors in processing csv file. var engine = new DelimitedFileEngine<ModelClass>; engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue; List<object> fileEngineResult = engine.ReadFile(fullFileName).ToList(); errorInfo = engine.ErrorManager.Errors; My ModelClass has the properties corresponding to each column in my csv file with validation attributes [DelimitedRecord(",")] [IgnoreEmptyLines] public class ModelClass { [FieldNotEmpty]

How to cast to a dynamic class?

Deadly 提交于 2019-12-12 03:08:40
问题 I am trying use filehelpersclass builder but I am kinda confused on what to do with it. var cb = new DelimitedClassBuilder("temp", ",") { IgnoreFirstLines = 0, IgnoreEmptyLines = true, Delimiter = "," }; var sr = new StreamReader(stream); var headerArray = sr.ReadLine().Split(','); foreach (var header in headerArray) { var fieldName = header.Replace("\"", "").Replace(" ", ""); cb.AddField(fieldName, typeof(string)); } var engine = new FileHelperEngine(cb.CreateRecordClass()); var result =

FileHelpers optional columns

旧巷老猫 提交于 2019-12-12 01:57:47
问题 I have static numbers of columns which my program will fill by data let's say 3. However at the end there could be additionally diffrent number of columns for pictures paths. At the moment i cannot say how many there will be as information will be comming from db so will be diffrent numbers of them. Question is how should i prepapre my class for that purpose? As you see below i declare 3 static columns but i have troubles how to do it for unknown number of pictures columns. Should i add 100

FileHelpers and SQL Insert with SqlServerStorage class ---How to show errors

北城以北 提交于 2019-12-12 01:43:47
问题 I am using the FileHelpers libraries to upload a CSV file to SQL Server. I would like to present the user with a list of records which could not be uploaded do to errors. I am setting the ErrorMode of the SqlServerStorage class to SaveAndContinue, however the InsertRecords method still throws an exception when one of the records violates a foriegn key constraint. Is there a way to save this error and continue with the insert? SqlServerStorage storage = new SqlServerStorage(typeof(RouteRecord)

How do upload and associate an image with another class simultaneously in MVC3

℡╲_俬逩灬. 提交于 2019-12-11 16:08:41
问题 I have a class, Event, and i want to be able to have images on the event page. I have defined the image class but am now sure how i can upload the image. I want to be able to store the image in the database. public class Event { public int Id { get; set; } public string Title { get; set; } public string Description { get; set; } public string Address { get; set; } public string AddressTwo { get; set; } public virtual Person Owner { get; set; } public DateTime Date { get; set; } public virtual

Dynamically create a Fixed Length text file with FileHelpers

谁都会走 提交于 2019-12-11 12:29:45
问题 FileHelpers supports a feature called "RunTime Records" which lets you read a Fixed length text file into a DataTable when you don't know the layout until runtime. Is it possible to use FileHelpers to export a Fixed length file at runtime in the same manner? 回答1: Here's a working sample for export using a DataTable as source. public static class DataTableExtensions { public static List<object> DataTableToList(this DataTable table, Type type) { List<object> list = new List<object>(); foreach

Filehelpers Excel to Oracle db

跟風遠走 提交于 2019-12-11 06:09:42
问题 I want to import excel data to oracle DB. I got enough help for Excel part, can you guys help me in Oracle side? Is it possible to import to oracledb with filehelpers? Please provide some sample code for reference. Thanks Dee 回答1: If you save the spreadsheet data as .csv files it is relatively straightforward to import it into Oracle using SQL Loader or external tables. Because we can use SQL with external tables they are generally eaiser to work with, and so are preferable to SQL Loader in