C# Read and Write to a Text File

Поделиться
HTML-код
  • Опубликовано: 23 ноя 2024

Комментарии • 72

  • @Joyosagsm
    @Joyosagsm 4 года назад +41

    I don't really have a question I just want to say this was a great video

    • @mortrem76
      @mortrem76 8 месяцев назад +1

      It is a great video

  • @MUSHIN_888
    @MUSHIN_888 2 месяца назад

    Thanks dude, this is exactly what I needed to learn for a lab question in my programming class at uni

  • @markyrocks69
    @markyrocks69 3 года назад +4

    Very useful video. I'm primarily a c++ user but you can't beat the ui building tools in c#.

  • @shwetachavan751
    @shwetachavan751 8 месяцев назад

    Thank you for so easy to understand videos. I had difficulty understanding this topic but after watching this video , I understood the topic very well. Thank you.

  • @gecko2023
    @gecko2023 2 года назад +3

    honestly, i've been doing coding for about 6 years now, and text files were a sort of, no go topic for me, this honestly made it seem so simple I feel a little stupid xD
    But in all seriousness, thanks mate, this has helped a lot

  • @InventorDBA
    @InventorDBA 3 года назад +1

    tip for anyone who is watching this: if you are using windows, in file explorer make your text file, click on the "home tab" on top, and click copy path. You don't have to manually copy the path every time.

  • @emiledanielbouwer6963
    @emiledanielbouwer6963 2 года назад +3

    Thank you. This was simple, helpful and using the list approach makes the class more versatile.

  • @Furki4_4
    @Furki4_4 2 года назад

    Thank you Prof Sluiter for precise explanation

  • @smoua4588
    @smoua4588 3 года назад

    Thank you so much Professor Sluiter

  • @jonlbs7
    @jonlbs7 4 года назад

    EXCELLENT !!! One of the best on just what I was looking for. 😊👍👌👍

  • @tprnbs
    @tprnbs 2 года назад

    Great tutorial! is it the same as using StreamReader/StreamWriter? Thanks!

  • @vusivuyanithemba797
    @vusivuyanithemba797 3 года назад

    You are the best, I am going to be a good C# programmer soon

    • @shadsluiter
      @shadsluiter  3 года назад

      Good to hear. How is your plan working out so far?

  • @alshentec2286
    @alshentec2286 2 года назад

    Do you have any tricky ways to save txt file as different names such as 123 while theere is already a txt file as that one thanks for your video

  • @frab8061
    @frab8061 5 лет назад +2

    I have a question, at the ending you're adding jon doe to the list and then writing the list to the file. But the other names were already in there. I thought there have to be the names from before plus the names from before again plus jon doe. Why is this not the case? Does the content of the file getting overwritten with File.WriteAllLines?

    • @shadsluiter
      @shadsluiter  5 лет назад +3

      Each time we run the program we do this (1) read all lines (2) add John Doe to the list of names (3) write the list back to the file. The file is overwritten each time. There is an option to the writeAllLines() method to either append or overwrite the file. Overwrite is the default choice if no parameter is provided. Check out the docs on the method here docs.microsoft.com/en-us/dotnet/api/system.io.file.writealllines?view=netframework-4.8

  • @mateeeje
    @mateeeje 2 года назад

    How to search for it. I have etc. John and he has number one after him and when i enter 1 to display john

  • @aravindswamy4742
    @aravindswamy4742 2 года назад

    Nice video. How will you bind the data for an employee registration form on the each text box that is named accordingly? When I tried doing the data binding, all the datas are binded on a single text box?

  • @codymckinney4934
    @codymckinney4934 Год назад

    i do this, but wondering whats the pros and cons to stream reader vs this

  • @FileFN3
    @FileFN3 Год назад

    I have a problem with the code :
    My file name and path are correct but it says it can not find it

  • @parsaabdolhossaini3978
    @parsaabdolhossaini3978 3 года назад

    great video, I learned something new today

  • @adamloepker8057
    @adamloepker8057 3 года назад

    saved me from a less than effective class cession

  • @douglasposho9299
    @douglasposho9299 3 года назад

    Keep up the good work

  • @OpTicMatrixJ
    @OpTicMatrixJ 4 года назад +1

    Great video sir thank you!!!

  • @magmyr
    @magmyr 4 года назад +1

    Hello Shad, thanks for a well explained video!
    I have one question thought, when i try to run my program to read the text file it throws me an error of access denied. Any idea how can i fix that?
    Thanks in advance!

    • @cossinle
      @cossinle 4 года назад

      Try running your application as adminstrator.

    • @magmyr
      @magmyr 4 года назад

      @@cossinle still get the same error. Any possible solutions i could try?

    • @magmyr
      @magmyr 4 года назад

      I fixed the problem. Thanks for the help!

    • @MaybeKian
      @MaybeKian 4 года назад +1

      @@magmyr why cant you say how you fixed it? there are ppl who have the same problem.

    • @hrishikeshgarud7177
      @hrishikeshgarud7177 3 года назад

      @@magmyr how

  • @thelinguafranca5421
    @thelinguafranca5421 2 года назад

    Hello, how can I return a specific line in all lines. Tnx

  • @kooyoung4866
    @kooyoung4866 3 года назад

    how do i delete words on the text instead of writing to it ?

  • @TonyDaExpert
    @TonyDaExpert 4 года назад

    I hope this is helpful making something in c# where I want to store an id and a date on a file line. With c++ (my native programming language) I could just get a for loop to go over each line and directly copy the set amount of values within each line into different variables (separate for ID and date) within an array

  • @umairjamshaid2173
    @umairjamshaid2173 4 года назад

    Super helpful. Thanks alot

  • @calvinking3355
    @calvinking3355 2 года назад

    Having an issue where filepath is denied access.
    I've tried it on multiple text files and still receive the same problem.
    The program reads the file just fine. It just doesn't write to it.
    Saw other people were experiencing the same thing was hoping for a quick fix. Using VS 2019 CE.

    • @calvinking3355
      @calvinking3355 2 года назад +2

      I fixed it. While the problem is common, the solution is not so much.
      Those who come across this problem, leave a reply and I'll share my fix.

    • @deathvaisen6381
      @deathvaisen6381 2 года назад

      @@calvinking3355 How to fix it man

    • @calvinking3355
      @calvinking3355 2 года назад

      @@deathvaisen6381 I just created a new folder through VS2020E. That will allow you to read and write only to the folder that was created through the program. Basically, my CPU didn't acknowledge permissions so reading/editing/appending were confined to the program's own environment.
      Hope that helps!

  • @yoshikiyamaguchi5295
    @yoshikiyamaguchi5295 5 лет назад

    I have a question. After I read the textfile, if I wanted to write the same thing in a different format, how could I do that?
    For example, now my textfile says
    116
    11/2/2012 18:22
    N9 45.483 E10 30.495
    416 m
    Now I want to write them to another file in the following manner
    116, 11/2/2012 18:22, N9 45.483 E10 30.495, 416m
    How could I make it so that all the information are lined up in one line, and separate them with " , " ?

    • @shadsluiter
      @shadsluiter  5 лет назад

      You can join strings in C# very easily. Here is a good page to explain it docs.microsoft.com/en-us/dotnet/csharp/how-to/concatenate-multiple-strings

  • @minetomek
    @minetomek 4 года назад +1

    Thanks for info. :)

  • @kellothermes5090
    @kellothermes5090 2 года назад

    It's only showing FileNotFoundException . How should I resolve this exception ?

    • @shadsluiter
      @shadsluiter  2 года назад +1

      It could be that the file is named differently than what it appears. Check to see that file extensions are visible on your computer. The file may be called filename.txt.txt instead of filename.txt

    • @kellothermes5090
      @kellothermes5090 2 года назад

      @@shadsluiter Thank you , that was exactly what was happening.

  • @bharanivasanthbca4756
    @bharanivasanthbca4756 3 года назад

    Tanx for the information

  • @haydenstuteville9423
    @haydenstuteville9423 5 лет назад

    It didn't show me my combos (my list) it just showed alot of system.string stuff can you help?

    • @shadsluiter
      @shadsluiter  5 лет назад

      Perhaps you need a toString() method defined in the class/object you are trying to display. Here is a good link to explain it ruclips.net/video/TYsiP_l5Ysg/видео.html

  • @jonlbs7
    @jonlbs7 3 года назад

    Where's the next one? You mentioned "in a future video .." and then I can't find it..

    • @davidheizer6232
      @davidheizer6232 3 года назад

      ruclips.net/video/EY7IdBDl4PI/видео.html

  • @pje_
    @pje_ 2 года назад

    How to read and write to EXE FILE?

  • @randomtopicvideos3957
    @randomtopicvideos3957 4 года назад

    Can you help me, i have this error, System.UnauthorizedAccessException,how should i fix this

    • @equation1321
      @equation1321 4 года назад +1

      staccoverflo

    • @thedude4039
      @thedude4039 4 года назад +1

      Perhaps the location of the file is not accessible by the user you are using on your computer. Try making whichever outlook account you are signed onto your computer as, admin. If this doesn't work, idk. If you're on mac, idk.

  • @nynthes8488
    @nynthes8488 2 года назад

    thanks bush

  • @palkay875
    @palkay875 3 года назад

    Good video thx

  • @Wonglamai
    @Wonglamai 4 года назад

    thank you

  • @exile3965
    @exile3965 4 года назад

    Good video thanks

    • @shadsluiter
      @shadsluiter  4 года назад

      So nice of you

    • @exile3965
      @exile3965 4 года назад

      shad sluiter your welcome dude

  • @debprosad6890
    @debprosad6890 3 года назад

    nice

  • @mqrvmckl3504
    @mqrvmckl3504 4 года назад

    Very helpfull

  • @kacper2246
    @kacper2246 4 года назад

    what does the @ before the string mean?

    • @pedro2mnunes
      @pedro2mnunes 3 года назад

      The @ character specifies a string as a verbatim literal string. In this way you can use characters like \ without escape characters.

    • @kacper2246
      @kacper2246 3 года назад +1

      @@pedro2mnunes that is actually very useful, thanks
      :)

  • @BKadezabek
    @BKadezabek 4 года назад

    Thanks :D

  • @Noah.Nation
    @Noah.Nation 2 года назад

    Doesn't work :/

  • @brockbillings4299
    @brockbillings4299 4 года назад

    Great video, but on a completely unrelated note this guy looks so much like kronos from god of war

  • @sagarwalishetti1176
    @sagarwalishetti1176 4 года назад

    Thank you