Questions tagged [csvhelper]

The CsvHelper library is a .NET library that allows for easy reading and writing of comma-separated values (CSV) files.

The CsvHelper library is a .NET library that allows for easy reading and writing of comma-separated values (CSV) files. The library aims to be fast and easy to use. One of the most notable features is that it allows reading of writing of objects directly from/to a .csv file.

Links

861 questions
146
votes
6 answers

In C#, how can I create a TextReader object from a string (without writing to disk)

I'm using A Fast CSV Reader to parse some pasted text into a webpage. The Fast CSV reader requires a TextReader object, and all I have is a string. What's the best way to convert a string into a TextReader object on the fly? Thanks! Update- Sample…
Hairgami_Master
  • 5,429
  • 10
  • 45
  • 66
72
votes
6 answers

CsvHelper not writing anything to memory stream

I have the following method: public byte[] WriteCsvWithHeaderToMemory(IEnumerable records) where T : class { using (var memoryStream = new MemoryStream()) using (var streamWriter = new StreamWriter(memoryStream)) using (var…
Ian Cotterill
  • 1,667
  • 4
  • 18
  • 28
44
votes
3 answers

CsvHelper changing how dates and times are output

I am using CsvHelper to write some CSV files and want to change the format of my dates and times to something specific. Following the advice from https://stackoverflow.com/a/31817621/223742 I can successfully create maps for each of my…
TheEdge
  • 9,291
  • 15
  • 67
  • 135
42
votes
4 answers

Using CSVHelper to output stream to browser

I'm trying to use CSVHelper to generate a CSV file and send it back to a browser, so the user can select a save location and filename and save the data. The website is MVC based. Here' the jQuery button code I'm using to make the call (data is some…
Bob Tway
  • 9,301
  • 17
  • 80
  • 162
37
votes
3 answers

In CsvHelper how to catch a conversion error and know what field and what row it happened in?

I am using the class CsvReader successfully and am happy with it, however, the file that I consume is being produced by a group which changes column formats without letting me know. So, one moment everything is working, then the next morning things…
t316
  • 1,149
  • 1
  • 15
  • 28
36
votes
2 answers

What is the best way to get the list of column names using CsvHelper?

I am trying to use CsvHelper for a project. I went through the documentation but I couldn't find a way to read all the column names with a single method. How can I get a list of all column header names easily with CsvHelper? I am doing it like this…
B A
  • 1,089
  • 2
  • 14
  • 24
35
votes
1 answer

Why can't I convert from 'System.IO.StreamWriter' to 'CsvHelper.ISerializer'?

Trying to write the contents of people to a CSVfile and then export it, however I am getting a build error and its failing. the error is: cannot convert from 'System.IO.StreamWriter' to 'CsvHelper.ISerializer' Not sure why this is happening unless…
dros
  • 1,217
  • 2
  • 15
  • 31
31
votes
3 answers

Parse CSV where headers contain spaces with CsvHelper

I have a CSV file with field headers and some of them contain two or three words separated by spaces: You can see in the above picture the field headers that contain spaces: "Time of Day", "Process Name", and "Image Path". When I tried to read the…
E235
  • 11,560
  • 24
  • 91
  • 141
29
votes
3 answers

CsvHelper Ignore case for header names

I have some class public class Import { public DateTime Date { get; set; } public string Category { get; set; } } In csv file header names can be in lowercase. How I can ignore case while reading file? var reader = new…
Starter
  • 329
  • 1
  • 3
  • 9
29
votes
6 answers

Read all values from CSV into a List using CsvHelper

So I've been reading that I shouldn't write my own CSV reader/writer, so I've been trying to use the CsvHelper library installed via nuget. The CSV file is a grey scale image, with the number of rows being the image height and the number columns the…
Ayb4btu
  • 3,208
  • 5
  • 30
  • 42
28
votes
7 answers

JSON string to CSV and CSV to JSON conversion in c#

I'm working with JSON/CSV files in my asp.net web API project and tried with CSVHelper and ServiceStack.Text libraries but couldn't make it work. The JSON file containing an array is dynamic and may have any number of fields I read the file using…
Priyanka Rathee
  • 1,077
  • 2
  • 13
  • 19
27
votes
4 answers

Write to a File using CsvHelper in C#

I tried to write to CSV file using CsvHelper in C#. This is the link to the library http://joshclose.github.io/CsvHelper/ I used the code in web site. Here is my code: var csv = new CsvWriter(writer); csv.Configuration.Encoding =…
Nayana Priyankara
  • 1,392
  • 1
  • 18
  • 26
26
votes
2 answers

How to create the C# mapping class to csvhelper

I have a csv file with 40 columns and I want to load it to a datatable using csvhelper. After installing the library, I did this: using (TextReader reader = File.OpenText(fileName)) { var csv = new CsvReader(reader); while (csv.Read()) { …
Agnieszka Polec
  • 1,471
  • 6
  • 20
  • 26
23
votes
3 answers

Dynamic creation of columns using csvHelper

I have a worker with various fields that are fetched from server. I am using CSVHelper package to convert this class to an excel sheet. Worker has Fields like : class Worker { string name; string phone; string age; …
hyoyin_Kyuoma
  • 643
  • 1
  • 6
  • 16
22
votes
9 answers

Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.0

I recently installed CsvHelper (https://joshclose.github.io/CsvHelper/) when i try to use the library I get the following error: Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral,…
Ismail
  • 923
  • 2
  • 12
  • 29
1
2 3
57 58