C# File
System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Threading;
using System.Windows.Forms;
namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
CreateDictionary(@"C:\TestDir_phileo");
addRecord("phileo", "Name1", "50", "C:/TestDir_phileo/TestDir_phileo.csv", true);
// Directory.CreateDirectory("./test");
CreateDictionary(@"C:\TestDir_phileo");
System.Timers.Timer a = new System.Timers.Timer();
// DateTime GetNowDateTime = DateTime.Now;
// String Path = @"C:\TestDir_phileo\MyTest.txt";
string FilePathName = @"C:\TestDir_phileo\"+"MyTest.txt";
if (!File.Exists(FilePathName)) { using (FileStream fs = File.Create(FilePathName)) { } }
using (StreamWriter sw = File.AppendText(FilePathName))
{
sw.WriteLine("This");
sw.WriteLine("is Extra");
sw.WriteLine("Text");
Thread.Sleep(1000);
sw.WriteLine(DateTime.Now);
}
}
private bool CreateDictionary(string dirPath)
{
//string dirPath = @"C:\TestDir";
if (Directory.Exists(dirPath))
{
Console.WriteLine("The directory {0} already exists.", dirPath);
}
else
{
Directory.CreateDirectory(dirPath);
Console.WriteLine("The directory {0} was created.", dirPath);
}
return true;
}
public static void addRecord (string ID, string Name, string age, string filepath, bool Append)
{
try
{
using (StreamWriter file = new StreamWriter(@filepath, Append))
{
file.WriteLine(ID + "," + Name + "," + age);
}
}
catch(Exception ex)
{
throw new AppDomainUnloadedException("OOps" + ex);
}
}
}
}