I just started using your package today but I can't figure out how to easily get the FieldHeaders.
I see some issues that include csv.FieldHeaders but I can't seem to find that in the code or any documentation. What is the simplest way for me to get the FieldHeaders using your library?
I'm currently using v3.0.0-chi06 and netcore v2.0.0
Thanks.
Which version are you using? What object are you using? In old versions it
should be accessible directly on the reader object. In the latest version
it should be accessible on the context on the reader.
Linking a gist or pasting some code would enable us to more accurately
answer the question.
On Aug 24, 2017 8:44 PM, "Codehhh" notifications@github.com wrote:
I just started using your package today but I can't figure out how to
easily get the FieldHeaders.I see some issues that include csv.FieldHeaders but I can't seem to find
that in the code or any documentation. What is the simplest way for me to
get the FieldHeaders using your library?Thanks.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/JoshClose/CsvHelper/issues/737, or mute the thread
https://github.com/notifications/unsubscribe-auth/AD_ohe9lOzGer9FPlLC1IY7EMVSBAIelks5sbhjRgaJpZM4PCGSq
.
@jamesbascle
Sorry, I forgot to include the version I was using in my original post but I ninja edited after realizing.
I'm using v3.0.0-chi06.
My code currently looks like the following:
var csv = new CsvReader( textReader );
csv.Read();
csv.ReadHeader();
var header = csv.FieldHeaders; // Doesn't exist?
var records = csv.GetRecords<MyClass>();
var header = csv.Context.HeaderRecord;
Thank you!
No problem!
This solution doesn't work for me. It errors with:
{"Method not found: 'CsvHelper.ReadingContext CsvHelper.CsvReader.get_Context()'."} | System.MissingMethodException
I've using the latest version fromthe nuGet package.
Is there another way to get the header data?
I've had to hardcode the header data to get this to work.
please get back to me. This is the first time I've used csvhelper, and it looks great, but failing to access header data is a big problem. The header data is in the FieldHeaders list, but not worth much if we cannot access it.
I have tried the following and it works just fine for me with the current version of CsvHelper.
var csv = new CsvReader( textReader );
csv.Read();
csv.ReadHeader();
var header = csv.Context.HeaderRecord;
var records = csv.GetRecords<MyClass>();
Thx for getting back to me, this is strange I tried the code below and it caused an error.
using (TextReader reader = File.OpenText(fnamePath))
{
var lp = 1;
CsvReader csv = new CsvReader(reader);
csv.ReadHeader();
var header = csv.Context.HeaderRecord;
while (csv.Read())
{
ImportCSV Record = new ImportCSV();
Record.FilterStatus = csv.GetField(0);
Record.FilterSysteem = csv.GetField(1);
Record.FilterType = csv.GetField(2);
Record.FilterKleur = csv.GetField(3);
Record.Category = csv.GetField(4);
Record.ProductName = csv.GetField(5);
Record.Model = csv.GetField(6);
Record.LegancyItemId = csv.GetField(7);
Record.Code = csv.GetField(8);
Record.Price = csv.GetField(9);
Record.Discount = csv.GetField(10);
Record.NetPrice = csv.GetField(11);
importList.Add(Record);
}
lp += 1;
}
Do you have any idea why?
You need csv.Read(); before csv.ReadHeader();. Also what error are you getting?
Ah!!! OK thx, I assumed the read header was independent or the read. I'll give this a try. Thx for your help.
The error was written above:
{"Method not found: 'CsvHelper.ReadingContext CsvHelper.CsvReader.get_Context()'."} | System.MissingMethodException
But I'll give the read before a try and let you know what happens.
Your issue may have to do with conflicting versions in your project. stackoverflow
A MissingMethodException almost always means that your application is running using a different version of an assembly than the assembly used to compile it against.
In this case it happened because another project, referenced by your main application, used an older version of the CsvHelper library, where that property wasn't present and thus its getter method wasn't found.
Make sure all projects in your solution reference the same version of the library, so its assemblies won't get overwritten with an older version on build.
OK, I'm running this in a DNN CMS. So I suppose it's possible, but I'm not aware of DNN using this, in fact I'm fairly sure it doesn't. But maybe I've overwritten an older version added by a module that was installed. I'll investigate. Thanks Again.
You are correct. There is a module on the site which installs v2, I should have seen this before.
Thank you for your help.
Most helpful comment