private void WriteTextFile()
{
string FileLoc = "C:\\LOGFOLDER\\TextFile.txt";
//This will create the new file if the file is not exist.
if (!File.Exists(FileLoc))
{
using (StreamWriter sw = File.CreateText(FileLoc))
{
sw.WriteLine("My Content Data");
}
}
//This will append to the existing file if the file already exist.
else
{
using (StreamWriter sw = new StreamWriter(FileLoc, true))
{
sw.WriteLine("My Content Data");
}
}
}
{
string FileLoc = "C:\\LOGFOLDER\\TextFile.txt";
//This will create the new file if the file is not exist.
if (!File.Exists(FileLoc))
{
using (StreamWriter sw = File.CreateText(FileLoc))
{
sw.WriteLine("My Content Data");
}
}
//This will append to the existing file if the file already exist.
else
{
using (StreamWriter sw = new StreamWriter(FileLoc, true))
{
sw.WriteLine("My Content Data");
}
}
}
No comments:
Post a Comment