Search code examples
c#.netfilehelpers

Storing the RecordString with the FileHelper Class


We are using FileHelpers 2.0 in our project. I have my record defined and have the data being imported correctly. After getting my array of generic objects:

var engine = new FileHelperEngine<UserRecord>();
engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;
UserRecord[] importedUsers = engine.ReadFile(_filepath);

After getting the records that errored due to formatting issues, I am iterating through the importedUsers array and doing validation to see if the information being imported is valid.

If the data is not valid, I want to be able to log the entire string from the original record from my file.

Is there a way to store the entire "RecordString" in the UserRecord class when the FileHelperEngine reads each of the records?


Solution

  • We do that often at work handling the BeforeRead event and storing it in a field mOriginalString that is marked this way:

    [FieldNotInFile] public string mOriginalString;

    You must use the last version of the library from here:

    http://teamcity.codebetter.com/repository/download/bt65/20313:id/FileHelpers_2.9.9_ReleaseBuild.zip

    Cheers