need help to figure out how handling following scenario.
We have a .NET application using FileHelpers library to parse CSV files. We don't use physical files, instead we have a SQL server database where CSV files are stored in a VARBINARY field. What we have to do is reading binary content using a stream reader and parse it with a proper multirecord engine.
Our CSV files use semicolon (;) as a separator character, but file records may contain escaped separator, where the escape character is exclamation mark (!). Escaped separator characters must be ignored when parsing file. This means that following records must be parsed the same way:
Hello;World;Foo //no escaped separators here
Hello!;;World;Foo!; //two escaped separators here
Both records of previous examples are valid and must produce an object whose properties are "Hello", "World" and "Foo".
Using the answer given to a previous question on this same site (FileHelper escape delimiter) I tried to subscribe public event BeforeReadRecord of MultiRecordEngine class, using an event handler that simply replace all occurences of "!;" with empty string.
This works fine when using MultiRecordEngine.ReadString method: event BeforeReadRecord is fired every time a record is read, event handler is called as expected and escaped separator characters are replaced with empty strings.
Unfortunately, when using MultiRecordEngine to read from a stream, event BeforeReadRecord is not fired at all and event handler code is never executed. I guess there is no way to take advantage of BeforeReadRecord event when reading from stream.
According to FileHelpers library documentations (http://filehelpers.sourceforge.net/FileHelpers.MultiRecordEngineMembers.html) it seems there is no proper event to use in this scenario.
Does anyone know a way to handle escaped separators when reading from a stream ?
Thanks for helping.
Enrico.