sabato 4 luglio 2009

How To: Write File C#

Come si fa a scrivere in un file in C# ?


string text = "testo da scrivere nel file.";
TextWriter tw = new StreamWriter ("c:/test.txt");
tw.WriteLine(text);
tw.Close();
tw = null;


E come si fa a scrivere un file in Append ?

string newText = "Testo in append";
TextWriter twAppend = new StreamWriter("c:/test.txt",true);
twAppend.WriteLine(newText);
twAppend.Close();
twAppend = null;

Nessun commento: