Hi All,
I'm trying to detect if a file exists at runtime, if not, create it. However I'm getting a 'The process cannot access the file 'myfile.ext' because it is being used by another process.' error when I try to write to it.
  string filePath = string.Format(@"{0}\M{1}.dat", ConfigurationManager.AppSettings["DirectoryPath"], costCentre); 
  if (!File.Exists(filePath)) { 
    File.Create(filePath); 
  } 
  using (StreamWriter sw = File.AppendText(filePath)) { 
    //write my text 
  }
Any ideas how to fix it?
Thanks