Possible Duplicate:
Cant Access File because it is being used by another process
using (StreamWriter _SelectedFile = File.CreateText(CConstant.m_TEMPFILEPATH))
{
_SelectedFile.WriteLine(CConstant.m_SaveFileDefaultDirectory);
_SelectedFile.WriteLine(CConstant.Tempfile_ECUSelected);
_SelectedFile.WriteLine(CConstant.Tempfile_inifile);
_SelectedFile.WriteLine(CConstant.Tempfile_mapfile);
_SelectedFile.Flush();
_SelectedFile.Close();
_SelectedFile.Dispose();
}
When running the code, the very first time when i run the code(There is no temp.txt file ) , it throws an exception "The process can't access the file, because it is being used by another process."Please suggest a solution and also what's wrong in writing the code this way?