Search code examples
c#file-ioasp.net-webpages

How to manipulate text file in WebPages (cshtml)?


How to manipulate file using WebPages (.cshtml)? In PHP we have fopen and other functions, what are the counterparts?


Solution

  • In .NET you have the System.IO.File class. So for example if you wanted to read the contents of some text file in a variable:

    @{
        string contents = File.ReadAllText(@"c:\work\foo.txt");
    }