in my little console app for c# I have to write to a file, and if it is not there i have to create it. It works fine when the file is already created, but when i try and create the file then write to it i get a System.IO.IOException saying the file is in use elsewhere.Here is what i've been using
if (!File.Exists(FilePath))
{
File.Create(FilePath);
}
FileInfo file = new FileInfo(FilePath);
using (TextWriter tw = new StreamWriter(file.Open(FileMode.Truncate)))
{
tw.Write(filePresent);
tw.Close();
}