Intro to the CsvHelper Library for C#

  Рет қаралды 27,484

IAmTimCorey

IAmTimCorey

Күн бұрын

Пікірлер: 114
@joeprincipato5211
@joeprincipato5211 Жыл бұрын
I am on Windows 11 , getting error after extracting zipfile. And trying to open csv file 0x80004005.. however any csv on my machine opens up no problem, I will try to use one of those, no big deal , just curious if anyone else had that
@pawel89pawel
@pawel89pawel Жыл бұрын
Never used it before but I have a feeling in my gut that in a matter of couple of months it will come in handy for one of my projects. Very fast and easy to use library. Thanks for sharing it. What interested me the most is this IEnumerable and ToList(). Does it also apply for getting the data from the database? Say for example I load 2000 records from the database for whatever reason say it would be a historical changes of some sort so it would be much more efficient to leave it as IEnumerable and create a virtualized table out of it (in blazor) rather then put it to the list and then create a virtualized table? Have you got any video that shows those differences? When to use what and so on? Also thanks for sharing github copilot chat. I think it will come in very handy.
@swordblaster2596
@swordblaster2596 Жыл бұрын
Fantastic library. DO NOT ROLL YOUR OWN CSV PROCESSING CODE. You are wasting your time.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Thanks for sharing!
@yomer355
@yomer355 Жыл бұрын
Yeah, CSV is such a simple format that you might not even think of using a library at first, but that would be a mistake.
@CodeZeeZ
@CodeZeeZ Жыл бұрын
Well... I wish I knew this some time before. That tool looks really good to work with.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Better late than never, I guess.
@markitus900
@markitus900 Жыл бұрын
Thanks sir Tim. Is there some manner to update and prevent real time about it?
@IAmTimCorey
@IAmTimCorey Жыл бұрын
I am not sure what you mean by "update and prevent real time". Can you please explain?
@markitus900
@markitus900 Жыл бұрын
@@IAmTimCorey i mean if is possible notify the changes on the csv somehow
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Not using this tool. You would need to tap into the file system events to monitor for file changes, but my guess is that those events won't be as granular as you like. They will tell you the file changed, but not what changed. You will need to read the entire file to figure out what changed by comparing it to what you are storing in memory (or another file) to see what the changes are. If you want change tracking, you might want to use a database.
@kiwibazza99
@kiwibazza99 14 күн бұрын
Great video lesson. As usual clear and concise! I currently have a set of PowerShell scripts that interrogate and import CSV data from production equipment into SQL. I plan to replace those clunky files with code using CSV Helper. Thanks again...
@IAmTimCorey
@IAmTimCorey 12 күн бұрын
I’m glad it was helpful.
@abdallabenomran6809
@abdallabenomran6809 Жыл бұрын
the best man in USA . Thanks a lot.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome!
@SoundOfHeavenStudio
@SoundOfHeavenStudio Жыл бұрын
Thank you for sharing, always love watching your tutorials! Btw, thanks to your paid courses (and here on yt also) I was able to build up enough experience and resumé that I am now hired full time as a full-stack developer 🎉
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Fantastic! Thanks for sharing!
@noahg2
@noahg2 Жыл бұрын
finally.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Hope you get value out of it.
@michelspijkvan2878
@michelspijkvan2878 Жыл бұрын
Csv files are allways problematic. The main reason is that Excel outputs Csv, in non-english versions, as ;-separated ot tab-separated. Also date formats are usualy expected in mm/dd/yyy format, while Excel outputs dd-mm-yyyy. And similair for numerics, the decimal and thousands separators are usually swapped.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
I find that Excel is more useful to view CSV files rather than creating them in the first place. Usually if you are creating something in Excel, it is an XLSX file.
@delw1138
@delw1138 Жыл бұрын
These tutorials on useful libraries are great, please do more of them.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Glad you like them!
@Matzul98
@Matzul98 Жыл бұрын
How can I deal with column name changes? If over time column names change and maybe their order. Or some are removed. Then I need some backwards compatibility between old reports in my app and new reports with the ever changing new format. When I download different formats that must map to the same class. 1. If the column header is dynamic in name then I can use regex. 2. If some columns are removed in the future I can use nullable properties.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
That's something you would need to write the logic for. It isn't something that the tool can do for you.
@scdecade
@scdecade Жыл бұрын
Another banger Tim. Been using CSVHelper for years and it's excellent
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Thank you!
@VeggehGaming
@VeggehGaming Жыл бұрын
This is going to be so useful for a future project of mine. So much quicker and I can already visualise the application! Thank you for showing this off!
@IAmTimCorey
@IAmTimCorey Жыл бұрын
I am glad it was helpful.
@optionstrader-r6l
@optionstrader-r6l 9 ай бұрын
Thank you .But ,Do we need to have any security concerns while using this kind of private NuGet packages as we don’t know what logic they have within their NuGet?
@IAmTimCorey
@IAmTimCorey 9 ай бұрын
You should always evaluate your dependencies, but I think the open source movement has actually confused people when it comes to their security. If you take on an open source (or source available) dependency, do you do a thorough code review of it? Or do you just assume because it is open that it is safe? Closed source doesn't mean unsafe. You can still review its outputs and actions to validate that it is doing what you think it should. For instance, the .NET Framework is not open source (.NET is open source). Visual Studio still isn't open source (and has no plans to be). The key isn't so much the availability of the source but in how much effort you put into evaluating the solution and if is something you are comfortable depending on. Long story short, the security concerns don't change based upon the availability of the source.
@joeyguerrieri3710
@joeyguerrieri3710 2 ай бұрын
Great Video! Your videos are so perfect! Is there a way I can download the cvs file? I host my apps on Azure. Thanks for your help!
@IAmTimCorey
@IAmTimCorey 2 ай бұрын
You would need to store the CSV file in a location where you can get it. Probably Azure Storage, since it is cheap and easy to use.
@bdi65
@bdi65 Жыл бұрын
as always great video and really helpful, thanks for share your knowledge.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Glad it was helpful!
@andergarcia1115
@andergarcia1115 Жыл бұрын
Master blessings, your content is the best, you have helped me a lot not to deviate from the path.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Glad to help.
@snapback9221
@snapback9221 Жыл бұрын
Tutorial did not rly show how the library really works. I hat this superficial, time wasting tutorials based on the documentation
@IAmTimCorey
@IAmTimCorey Жыл бұрын
In this tutorial, I created a CSV file using the library. I also read a CSV file into memory. I'm not sure what else you were looking for from an intro tutorial.
@dayne-kora2415
@dayne-kora2415 Жыл бұрын
Thank you Tim Corey. Your videos here have been a real guide for me in learning C# and now I've gotten promoted at work because of how fast I've learned. Thanks a lot
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Awesome! Thanks for sharing and congratulations!
@frankhaugen
@frankhaugen Жыл бұрын
CSV helper is missing tools for actually working on CSV data. It's an excellent mapper, but I miss having the data in a "datatable"-like structure as well, so I'm making it myself 😂
@IAmTimCorey
@IAmTimCorey Жыл бұрын
I don't think it is "missing" it. They purposefully chose not to include one because a CSV is not a database and cannot be treated like one. For instance, if you wanted to sort the data, you would need to load the whole CSV into memory. If you wanted to filter the data, you would need to load the whole CSV into memory. If you wanted to update a row, you would need to load the whole CSV into memory. That seems fine if you are loading 10,000 rows or less but it get messy when you try to load 1,000,000 rows. If you want database-like structure and capabilities, load the CSV into SQLite or another actual database. Then you can do whatever you want with the data without keeping the entire file in memory for the life of your application.
@spart230
@spart230 Жыл бұрын
Thanks again for the fantastic tutorial. The program throws a System.IO.IOException if someone or a different service opens the file while it's in the for loop. It is possible to have concurrent read access from multiple systems?
@IAmTimCorey
@IAmTimCorey Жыл бұрын
I don't believe that you can. I believe that's a limitation of Windows mostly, but I am not positive if there is anything you can do to change how you lock the file.
@spart230
@spart230 Жыл бұрын
Thank you very much for this wonderful video. I have a wpf application with a textbox and a listbox. The source data is a CSV file with approx 1million rows. The goal is to filter the CSV for the data each time a user enters data in the textbox. Is there a performance cost to open, read and filter a file stream each time the user enters a text vs just having it in RAM? Is there a better way to solve this problem?
@IAmTimCorey
@IAmTimCorey Жыл бұрын
There is a major performance issue here. You would need to put all 1,000,000 records into memory in order to filter them. In theory, you could discard the non-matching records so you don't have to keep them in memory, but that's only true if you don't allow the user to backspace in the search field. If they did, you would need to re-process all 1,000,000 rows again. The better option here is to load that data into a database with indexes. It will take a while, but after that, you can easily query the data. That's why databases are so powerful compared to just text files.
@terjes64
@terjes64 Жыл бұрын
Nice. I'm sure that I have mapped at least 20 times manually. Guess it does not work directly on excel files aswell?
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Nope, but there are libraries for working with Excel files, though: kzbin.info/www/bejne/oGS2ZJR_bdOAm6c
@terjes64
@terjes64 Жыл бұрын
@@IAmTimCorey okay would be nice if it just had the option to convert excel to csv
@demariners
@demariners Жыл бұрын
So, I noticed briefly in this video you showed CoPilot producing Attributes. Do you have a video that explains them and how to use them manually? I have looked everywhere to understand how this work with no success.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
How to create attributes? No, I don't have a video on that. Copilot was just suggesting I use existing attributes, though.
@demariners
@demariners Жыл бұрын
Thanks for the reply! You have taught me so much you have NO idea. I have made an entire application that I sell now because of you. I can not thank you enough! Yes, attributes. Maybe one day you can make a 10-min short on them as I can not find anything on them. I know there is also a way to use them to import C++ libraries and I also have no clue how to do that.@@IAmTimCorey
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
@Norman_Fleming
@Norman_Fleming Жыл бұрын
Talking efficiency/fast while having a console writeline in a loop kind of defeats what you are trying to show. Does this CsvHelper handle embedded CRLF and all the other oddities which exist in the real world? Can it also support other delimiters, not just a comma? Guess I could check the doc. More importantly how do you or anyone trust nuget packages? Seems like a trojanHorseFactory.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
1. That’s how demos work. 2. Yes, it can handle the oddities of CSV files. 3. Trust NuGet packages? That’s how C# works. Even Microsoft uses them for their core products. For open source products (like this one), you can inspect the source yourself. For closed source, you can evaluate the company that supports them. It is no different than trusting any other software or app.
@LassahDK
@LassahDK Жыл бұрын
Thank you Tim for an awesome walkthrough and guide. I've noticed on a few of your videos that when you type ie Console.WriteLine($"") at 14:40 you get a small grey box with a type (value)(text) inside it. What does that?
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Here is a video showing you how to turn those on: kzbin.info/www/bejne/o6DVc36nqdagqdEsi=CLUYrvvEaqPpZE_v
@markbennett1237
@markbennett1237 Жыл бұрын
The reason why I searched for this is because some of the fields that I am working with may be enclosed in quotes, and the content between the quotes can contain commas. I don't want these commas to be interpreted as field separators. Also, I didn't want the quotes to be included in parsed strings. I assume CSVHelper can handle these sorts of things. I'll give it a try. Thanks for the video.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Yep, it can. CSV files can get quite complex, but this library handles it.
@Detyrious
@Detyrious Жыл бұрын
Just a little feedback, but in my opinion it would be better if GitHub Copilot and other AI helper would be deactivated for these videos. It's a great tool, but I watch your videos to learn the details and understand them fundamentally - and you still do that, but when the AI is spitting out entire chunks of code I just think it hurts these kind of videos more than it helps. Just IMHO.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Thanks for sharing!
@andywalter7426
@andywalter7426 Жыл бұрын
I have a question. I would think a person is always supposed to use .ToList. I have found many cases where you had many memory leaks unless you used ToList. I would think libraries should always return a list and never ienumerable so if a person uses it in many ways, then it does not have to reprocess everything again.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Yield cannot work with List. To make it return List would be to destroy its efficiency. ToList would put the entire CSV in memory. IEnumerable and Yield allows the helper to only put in memory the row being returned.
@yomer355
@yomer355 Жыл бұрын
FileHelpers is another good library for processing CSV files, and unlike CsvHelper it's not under a copyleft license.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Thanks for sharing!
@vaibhavtrikolikar4902
@vaibhavtrikolikar4902 Жыл бұрын
Thanks for sharing such great concept about CSV file Library , Request you to please make series of all C# Library
@IAmTimCorey
@IAmTimCorey Жыл бұрын
I'm glad you enjoyed it.
@runtimmytimer
@runtimmytimer Жыл бұрын
I’m currently using a different library but this looks better. I’ll be looking to add a feature where I don’t know the columns or the order. Hopefully this library supports this. I’ll need to create the mapping at runtime from user input.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
I am glad it was helpful.
@cormackeenan8175
@cormackeenan8175 Жыл бұрын
Hi i’ve encountered a problem the code creates the file but no records are in it 🤷‍♂️😤 What have i done wrong…HELP
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Not sure, but it sounds like a good opportunity to debug.
@cormackeenan8175
@cormackeenan8175 Жыл бұрын
@@IAmTimCoreyIt’s really weird if i remove the last line of code Console.Readline(); it will save the records to file, if I include this line it won’t 🤷‍♂️
@cormackeenan8175
@cormackeenan8175 Жыл бұрын
@@IAmTimCorey Using (var csvOut = new CsvWriter(writer, CultureInfo.InvariantCulture)) { csvOut.WriteRecords(outputRecords); } Console.Readline(); Will write the records to file, but it’s not the same as your code so what gives?
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You need to hit the Enter key and let the application complete before the file will be closed out properly with my code. With the above code, your using closes out before the application pauses to listen for user input.
@codefoxtrot
@codefoxtrot Жыл бұрын
Awesome demo. I have an integration coming up, which is using CSV data... so glad I caught this video first!!!
@IAmTimCorey
@IAmTimCorey Жыл бұрын
I am glad it was helpful.
@mahydulislam
@mahydulislam 4 ай бұрын
Thankyou for your nice explanation.
@IAmTimCorey
@IAmTimCorey 4 ай бұрын
You are welcome.
@IAmTimCorey
@IAmTimCorey 4 ай бұрын
You are welcome.
@maxedouthc
@maxedouthc Жыл бұрын
Awesome! Use case we have is, person drops csv, load csv into sql server table incrementally.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Excellent!
@gnarfish5555
@gnarfish5555 Жыл бұрын
Heavily used this library. Thank you for making a video to use this library.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
@Anton-Os
@Anton-Os Жыл бұрын
Thank you very much, may the grace of God come with you!!!
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Thank you!
@ajaykumark107
@ajaykumark107 Жыл бұрын
does it have protections against CSV Injection ?
@IAmTimCorey
@IAmTimCorey Жыл бұрын
That wouldn't apply here. CSV injection is only relevant when you are opening a CSV file in Excel or other systems where it processes the fields. In C#, you would just see the formulas, etc. as text. You could load, update, and save a CSV file full of CSV injection junk and it wouldn't affect your system in the slightest.
@caseyspaulding
@caseyspaulding Жыл бұрын
Much appreciated. Like seeing how you use Copilot
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Thanks!
@didierfolly
@didierfolly Жыл бұрын
A great video as usual! Thanks Tim and your team.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
@windowsbuilderthegreat3121
@windowsbuilderthegreat3121 Жыл бұрын
Is there a tsv equivalence to this library
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You can use tab-separated format instead of comma-separated using this tool.
@mrmuzeza113
@mrmuzeza113 Жыл бұрын
Thank you Mr Tim, for the great content
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
@pedrobelfort7003
@pedrobelfort7003 8 ай бұрын
muuito bom! obrigado professor!
@IAmTimCorey
@IAmTimCorey 8 ай бұрын
You are welcome.
@paul99782
@paul99782 Жыл бұрын
Is there a PDFHelper package like this? I've used the CsvHelper package before and found it VERY helpful! I wish there was a package that was just as easy for PDF.
@Mike-qu6fp
@Mike-qu6fp Жыл бұрын
The pdf format is very complicated so they all have fairly major drawbacks: price, license, complexity, compatibility, support, quality of output. My opinion is html is a better format for most use cases, although usually people want pdf anyway because it feels familiar.
@paul99782
@paul99782 Жыл бұрын
@Mike-qu6fp it definitely "feels" more familiar given that I've never worked with HTML and the company I work for uses PDF's like they're candy. If I am to print or visualize any files for the users, I'd need to use PDF. Maybe XPS, but that's its own can of worms 😅 I definitely get the issues with PDF, though, for sure.
@saulolima6874
@saulolima6874 Жыл бұрын
Thank you!
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
@ue9650
@ue9650 Жыл бұрын
Thank You!
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
@TurntableTV
@TurntableTV Жыл бұрын
I don't know how Tim's channel didn't reach millions of subs already. His content is top notch. I have used csvhelper but I did make that mistake of converting the records to a List. Thank you for showing me a better and efficient way to use this amazing library!
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
@ellayoung5293
@ellayoung5293 Жыл бұрын
If you want the data for other usage, it is fine to use tolist.
@andywalter7426
@andywalter7426 Жыл бұрын
If this does not use source generators to find the classes, then it would be too slow because reflection is always too slow.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You can look at the code to see how it is doing it, but it could absolutely use reflection and still be incredibly performant. Don’t get so locked into a technology that you fail to consider the alternatives.
@WondervilleSeries
@WondervilleSeries Жыл бұрын
I have not used CSV Helper yet but I have a project where it will come in handy. Thank you!
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
@email195
@email195 11 ай бұрын
Another great video Tim! I just used CsvHelper for a small project where I needed to generate a csv with checks printed from our accounting software for positive pay system with the bank. It was super easy to do. I had to eliminate the header row and format datetime into date only, but it had all the options to do so in a clean way. I used your video as a general guide to make it happen.
@IAmTimCorey
@IAmTimCorey 11 ай бұрын
I am glad it was helpful.
Intro to Records in C# 9 - How To Use Records And When To Use Them
1:19:44
C# Data Access: Complex Objects with Dapper
28:09
IAmTimCorey
Рет қаралды 29 М.
Brawl Stars Edit😈📕
00:15
Kan Andrey
Рет қаралды 59 МЛН
Как мы играем в игры 😂
00:20
МЯТНАЯ ФАНТА
Рет қаралды 3,2 МЛН
LIFEHACK😳 Rate our backpacks 1-10 😜🔥🎒
00:13
Diana Belitskay
Рет қаралды 3,9 МЛН
10 C# Libraries To Save You Time And Energy
33:59
IAmTimCorey
Рет қаралды 207 М.
The BEST Way to Read a CSV File in C# | CsvHelper Tutorial
9:41
Roberts Dev Talk
Рет қаралды 60 М.
Intro to Regular Expressions - How to use Regex in C#
55:52
IAmTimCorey
Рет қаралды 39 М.
Generating Fake Data in C# with Bogus
36:11
IAmTimCorey
Рет қаралды 23 М.
30+ String Manipulation Techniques in C#
1:44:07
IAmTimCorey
Рет қаралды 103 М.
How To Create Generics in C#, Including New Features
38:51
IAmTimCorey
Рет қаралды 48 М.
Intro To Class Libraries in C#
1:01:37
IAmTimCorey
Рет қаралды 75 М.
C# Logging with Serilog and Seq - Structured Logging Made Easy
1:07:56
The Easiest Way to Create PDFs in .NET
9:47
Nick Chapsas
Рет қаралды 117 М.