user406151
user406151

Reputation: 425

How do I create a text file on server or memory?

How do I create a text file and write the contents of a string to it? I plan to reference to the text file later. It could be on the server (root folder) or anywhere where I can reference it. Below is the string contents

 foreach (string s in strValuesToSearch)
            {

                if (result.Contains(s))

                    result = result.Replace(s, stringToReplace);

Upvotes: 0

Views: 335

Answers (2)

Quintin Robinson
Quintin Robinson

Reputation: 82375

As long as you have proper permission to write on the server you can take advantage of the methods of the System.IO.File class

System.IO.File.WriteAllText

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1039468

You could use the WriteAllText method:

string result = "foo bar";
File.WriteAllText(@"c:\foo.txt", result);

Upvotes: 2

Related Questions