Thursday, March 1, 2012

CSharp: how to write content to a file

Share at Facebook

I prefer two ways to write content into a output file. Below are those

1)System.IO.File.WriteAllLines(@"c:\output.txt", allLines);
Basically you have to combine all your lines into a single string, and then just dump inside the output file.

2) using the StreamWriter of IO.

System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\output.txt")
now using a loop, just execute the following line inside the loop.

No comments: