How would I go about saving a user form input from a view to an existing text file with the ASP.NET MVC framework?
1 Answer
So to start of, you would accept some code from the user and then save it:
string userInput =Console.Readline();
Then you would use the code WriteAllText(). This allows you to create a new file and writes the contents to it. If the file already exists, it will be overwritten.
So basically:
string userInput =Console.Readline();
File.WriteAllText("thenameyouwanttogivetoyourfile.txt", userInput);
This reads the file and then outputs it
string readText = File.ReadAllText("thenameyouwanttogivetoyourfile.txt");
Console.WriteLine(readText);
Thats how you create a new file. To overwrite a file that already exists, you do the same thing but with the keyword Create(). This creates or overwrites a file and if you want to replace the contents of one file with another, use Replace().
For futher help try this link: https://learn.microsoft.com/en-us/dotnet/api/system.io.file?view=netframework-4.8