Thursday, March 1, 2012

How to write content to a file in C#

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.
file.WriteLine(line);

No comments:

Get function name programaticaly - Python

This little piece of code will help you to get the function name programatically. This is very helpful when you are implementing the debug...