Reading content of text file c#




















Contents Exit focus mode. Is this page helpful? Please rate your experience Yes No. Any additional feedback?

Note The files that are used in this example are created in the topic How to write to a text file. So for this article we will place a text file having some text in file in wwwroot folder and then we will read the content of test file. Net , Asp. Now for this article first we will create a new asp. Now in your controller or class file add the below code. This piece of core will make you enable to read the passed text file present into your wwwroot folder.

GetDirectoryName Assembly. Location ;. Combine buildDir, filepath ;. ReadAllText filePath ;. Now before moving further we we need make some changes into the property of wwwroot added text file.

Now in property window we will set Copy to Output Directory as Copy if newer. Now we will write the code to read and display the text file content in your view. Method File. ReadAllText is implemented similarly to the following code.

The using statement ensures that method StreamReader. Again, the easy way is to use static class File and it's method File. If you look under the hood of the File. MoonKnight MoonKnight This is how I did it with a large 50 GB file: I tried 2 different ways: the first, reading the file into memory and using Regex Replace or String Replace. Exists outFileName File. ReplaceDoubleBrackets line ; sw. Append newstr ; return sb. IO; using System. ReadToEnd ; reader. Write content ; writer.

Ali Ali 12 12 silver badges 19 19 bronze badges. Text ; File. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually.

Linked 2. See more linked questions. Related Hot Network Questions. Question feed.



0コメント

  • 1000 / 1000