I am trying to write some text to the file using StreamWriter and getting the path for the file from FolderDialog selected folder. My code works fine if the file does not already exist. but if the file already exist it throws the Exception that the file is in used by other process.
using(StreamWriter sw = new StreamWriter(FolderDialog.SelectedPath + @"\my_file.txt")
{
sw.writeLine("blablabla");
}
Now if I write like this:
using(StreamWriter sw = new StreamWriter(@"C:\some_folder\my_file.txt")
it works fine with an existing file.