Create CSV file in C# the EASY way | CsvHelper Tutorial

Поділитися
Вставка
  • Опубліковано 8 жов 2024

КОМЕНТАРІ • 43

  • @RDT
    @RDT  3 роки тому

    We've now made an updated video that addresses some of your questions about handling semicolon delimiters and CSV files with no header row, check it out! ua-cam.com/video/f5bzNh7hVhk/v-deo.html

    • @kelvindai1994
      @kelvindai1994 2 роки тому

      Hi, i have a few question ?!
      1. Let's say i have an Child Class named Fuel of RocketInfo ( Fuel : RocketInfo ), how do i write it to a csv file along side with the parent class ( RocketInfo ) ?
      2. How do i read multiple .csv files in the same folder ?

  • @husseinadam4724
    @husseinadam4724 Рік тому +1

    I am really liking this channel thank you Robert

    • @RDT
      @RDT  Рік тому

      Thanks for your support

  • @gatocode316
    @gatocode316 22 дні тому +1

    simple and direct, thanks.

    • @RDT
      @RDT  17 днів тому

      You're welcome!

  • @kopilkaiser8991
    @kopilkaiser8991 2 роки тому

    Thanks for the video. I really pretty much understood everything you had shown and demonstrated.

  • @AlbrechtJ
    @AlbrechtJ 3 роки тому +1

    Your example is awesome. Thanks for the CsvHelper series.

    • @RDT
      @RDT  3 роки тому +1

      You’re welcome, glad you enjoyed it! I really like the library

  • @joffrelustosadoamaralmota6185
    @joffrelustosadoamaralmota6185 2 роки тому

    Nice! An idea for some other video, is showing how to work with both mapped and dynamic columns.

  • @sofianell2557
    @sofianell2557 3 роки тому +1

    Hello, please where does the newly created file goes ? Evrything compile OK, but i cannot find the file
    Thx

  • @patrickboehme4556
    @patrickboehme4556 2 роки тому

    Awesome video, thanks!

    • @RDT
      @RDT  2 роки тому +1

      Glad to hear you enjoyed it 😊

  • @indreeshpandey2025
    @indreeshpandey2025 Рік тому

    hi, can u please make a video on state pattern ex like stopwatch

  • @jamesallgood8506
    @jamesallgood8506 3 роки тому +1

    nice video. is there any way to sort the column heads vertically instead of the default horizontal line? I cant seem to figure it out

    • @RDT
      @RDT  3 роки тому +2

      As far as I can see, CsvHelper will always write column headers to the first line. However it does support writing dynamic/ExpandoObjects so you might be able to do something with that? You could create an IEnumerable populated with dynamically created objects that have the "column" name as the first property, and then add the other properties from your object after. That way the column names will be down the left hand side when you open up the file. If you then set the HasHeaderRecord = false on CsvConfiguration then it won't try to write a header line for you.
      Be careful when calling WriteRecords, make sure the type T on the IEnumerable is dynamic and not ExpandoObject, as it'll throw an exception.
      Hope that helps? Glad you enjoyed the video!

    • @jamesallgood8506
      @jamesallgood8506 3 роки тому +1

      @@RDT Nvm, the PO just changed the requirment as of today, so I am good with the normal layout. But thanks a lot, anyway :)

  • @AeroTesting
    @AeroTesting Рік тому

    Hi you can help me! i'm trying save .csv but first i Open .DAT File -> .csv save format! can you help?

  • @cirilla7283
    @cirilla7283 3 роки тому +1

    thanks

    • @RDT
      @RDT  3 роки тому +1

      You're welcome!

  • @harveyemmerson1568
    @harveyemmerson1568 2 роки тому

    Is there a way to target specific cells, i am creating a little finance program and i need to change the users balance that is stored within the CSV file, is there a way i can target just that specific cells when writing records?

  • @badrulhussain5545
    @badrulhussain5545 3 роки тому +1

    Hi is there a way to update the Environment.CurrentDirectory path. For example, if you have 3 projects in one solution and the 3rd project is a repository and you want the file to be saved in that 3rd project folder then the main project 1 that has the Controller?

    • @RDT
      @RDT  3 роки тому +2

      Hi Badrul, I just used the Environment.CurrentDirectory as an example to keep things simple, but if you had multiple projects perhaps you could use a ..\ to switch between folders e.g. $"{Environment.CurrentDirectory}..\RepositoryProject"

  • @egorzh3828
    @egorzh3828 3 роки тому +1

    Hi, please tell me how to change the delimiter?

    • @RDT
      @RDT  3 роки тому +1

      Hi EgorZH, thanks for your comment. You can change the delimiter by creating a new CsvConfiguration object and setting the Delimiter property, then passing that into the CsvWriter constructor instead of CultureInfo. I'll be uploading a new video soon which addresses this and a few other viewer questions :)

    • @egorzh3828
      @egorzh3828 3 роки тому +1

      @@RDT Thanks

  • @indreeshpandey2025
    @indreeshpandey2025 Рік тому

    hi,
    can u please tell how to find the average of the payload capacity?

    • @RDT
      @RDT  Рік тому +1

      You could use the built in .NET Linq methods. Select to get an enumerable of the Payload capacity column and then Enumerable.Average

  • @favela9348
    @favela9348 3 роки тому

    Hello, Thanks for the video, I have a problem with this line " return rocket.PayloadCapacity.HasValue ? $"{rocket.PayloadCapacity} kg" : String.Empty; " I don't know why I have this error : CS1061 'ConvertToStringArgs ' does not contain a definition for 'PayloadCapacity' and no accessible extension method 'PayloadCapacity' accepting a first argument of type 'ConvertToStringArgs ' was not found (a using directive or a reference assembly missing?) Can you help me :)
    Thanks

    • @favela9348
      @favela9348 3 роки тому

      And it's possible to display an array ?

  • @PaoloBoffi
    @PaoloBoffi 3 роки тому

    Hi, I don't know why but even following all the steps you have made my data are all inside the first element of the row in the .csv file, and not one for each column as in your example. Could you please help me?

    • @RDT
      @RDT  3 роки тому

      Hi Paolo, is your source file formatted OK? Are you using dynamics or a custom class with attributes/classmap?

    • @PaoloBoffi
      @PaoloBoffi 3 роки тому +1

      @@RDT hi, I managed yo solve. It was a problem with Excel, that I used to open the .csv file. It saw ";" as delimitation and not ","

    • @RDT
      @RDT  3 роки тому +1

      That’s great, happy to hear you got it sorted. You can also set the delimiter CsvHelper uses in Configuration

    • @PaoloBoffi
      @PaoloBoffi 3 роки тому +1

      @@RDT thank you again for your help :)
      And thank you for your videos :)

    • @RDT
      @RDT  3 роки тому +1

      You’re welcome!

  • @willchen5895
    @willchen5895 2 роки тому

    is this .net 5.0 ?

    • @RDT
      @RDT  2 роки тому

      This example was 3.1 github.com/chrismroberts/csvwriter-example/blob/main/CsvWriterDemo.csproj