Intro to the CsvHelper Library for C#

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ก.ย. 2024

ความคิดเห็น • 112

  • @dayne-kora2415
    @dayne-kora2415 ปีที่แล้ว +1

    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  ปีที่แล้ว +1

      Awesome! Thanks for sharing and congratulations!

  • @scdecade
    @scdecade ปีที่แล้ว +1

    Another banger Tim. Been using CSVHelper for years and it's excellent

  • @delw1138
    @delw1138 ปีที่แล้ว +2

    These tutorials on useful libraries are great, please do more of them.

  • @VeggehGaming
    @VeggehGaming ปีที่แล้ว +1

    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.

  • @SoundOfHeavenStudio
    @SoundOfHeavenStudio ปีที่แล้ว +5

    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!

  • @CodeZeeZ
    @CodeZeeZ ปีที่แล้ว +2

    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.

  • @abdallabenomran6809
    @abdallabenomran6809 ปีที่แล้ว +2

    the best man in USA . Thanks a lot.

  • @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.

  • @andergarcia1115
    @andergarcia1115 ปีที่แล้ว +1

    Master blessings, your content is the best, you have helped me a lot not to deviate from the path.

  • @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.

  • @gnarfish5555
    @gnarfish5555 ปีที่แล้ว

    Heavily used this library. Thank you for making a video to use this library.

  • @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.

  • @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.

  • @joeprincipato5211
    @joeprincipato5211 ปีที่แล้ว +3

    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

  • @didierfolly
    @didierfolly ปีที่แล้ว

    A great video as usual! Thanks Tim and your team.

  • @bdi65
    @bdi65 ปีที่แล้ว +1

    as always great video and really helpful, thanks for share your knowledge.

  • @mrmuzeza113
    @mrmuzeza113 ปีที่แล้ว

    Thank you Mr Tim, for the great content

  • @noahg2
    @noahg2 ปีที่แล้ว +2

    finally.

    • @IAmTimCorey
      @IAmTimCorey  ปีที่แล้ว

      Hope you get value out of it.

  • @caseyspaulding
    @caseyspaulding ปีที่แล้ว

    Much appreciated. Like seeing how you use Copilot

  • @Anton-Os
    @Anton-Os ปีที่แล้ว

    Thank you very much, may the grace of God come with you!!!

  • @pawel89pawel
    @pawel89pawel ปีที่แล้ว +1

    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.

  • @mahydulislam
    @mahydulislam 3 หลายเดือนก่อน

    Thankyou for your nice explanation.

    • @IAmTimCorey
      @IAmTimCorey  3 หลายเดือนก่อน

      You are welcome.

    • @IAmTimCorey
      @IAmTimCorey  3 หลายเดือนก่อน

      You are welcome.

  • @maxedouthc
    @maxedouthc ปีที่แล้ว

    Awesome! Use case we have is, person drops csv, load csv into sql server table incrementally.

  • @yomer355
    @yomer355 ปีที่แล้ว

    FileHelpers is another good library for processing CSV files, and unlike CsvHelper it's not under a copyleft license.

  • @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.

  • @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.

  • @pedrobelfort7003
    @pedrobelfort7003 8 หลายเดือนก่อน

    muuito bom! obrigado professor!

    • @IAmTimCorey
      @IAmTimCorey  8 หลายเดือนก่อน

      You are welcome.

  • @joeyguerrieri3710
    @joeyguerrieri3710 หลายเดือนก่อน

    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  หลายเดือนก่อน

      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.

  • @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.

  • @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: th-cam.com/video/morBKqtqmso/w-d-xo.htmlsi=CLUYrvvEaqPpZE_v

  • @markitus900
    @markitus900 ปีที่แล้ว +1

    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  ปีที่แล้ว +1

      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.

  • @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/

  • @saulolima6874
    @saulolima6874 ปีที่แล้ว

    Thank you!

  • @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  ปีที่แล้ว +1

      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.

  • @WondervilleSeries
    @WondervilleSeries ปีที่แล้ว

    I have not used CSV Helper yet but I have a project where it will come in handy. Thank you!

  • @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  ปีที่แล้ว +1

      Nope, but there are libraries for working with Excel files, though: th-cam.com/video/j3S3aI8nMeE/w-d-xo.html

    • @terjes64
      @terjes64 ปีที่แล้ว

      @@IAmTimCorey okay would be nice if it just had the option to convert excel to csv

  • @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.

  • @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  ปีที่แล้ว +2

      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.

  • @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  ปีที่แล้ว +1

      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.

  • @paul99782
    @paul99782 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      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.

  • @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  ปีที่แล้ว +1

      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.

  • @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.

  • @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.

  • @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.

  • @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  ปีที่แล้ว +2

      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.

  • @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.

  • @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.

  • @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.

  • @swordblaster2596
    @swordblaster2596 ปีที่แล้ว +1

    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.

  • @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.

  • @ue9650
    @ue9650 ปีที่แล้ว

    Thank You!