-2

I have the file path of a txt file inside a string. How do I put the text of this file into another string?

  • 1
    Microsoft also has a [guide on this](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/file-system/how-to-read-from-a-text-file). Searching ["C# read text file" on Google](https://www.google.com/search?q=c%23+read+text+file) brings up a ton of results. https://idownvotedbecau.se/noresearch/ – Jesse Jun 23 '22 at 21:30

1 Answers1

2

Use File.ReadAllText

    var path = "[yourPathHere]";
    var contents = File.ReadAllText(path);
Nigel
  • 2,961
  • 1
  • 14
  • 32