While working on some XSD validation code today, I found that I needed to load a couple of text files into strings to unit test. I’d forgotten how I’d done this before, but I googled the answer with this search term:
The top result (at least as of today), gave me the answer I needed. I’ve reproduced it as the following function:
Update: Ed Poore let me know in a comment that the .NET Framework contains a method that does this already. System.IO.File.ReadAllText(path) does the same thing, so you can completely ignore the method above.
You know this is already built into the framework? Check out:
Thanks very much for this. That shortens up my unit test class rather nicely.
Not a problem, no one can know then entire contents of the framework. Sometimes the strategy is to try and think like the developers and think how they would name something and Google it.
Glad I could be of some service.