I am getting this error when a new file is added to a folder:
The process cannot access the file 'C:\Folder\New Text Document.txt' because it is being used by another process.
I am trying to find a solutions here on SO but none has worked for me. My code at the moment now is:
private void fileSystemWatcher1_Created(object sender, FileSystemEventArgs e)
{
fileWatcher1.Items.Add(string.Format("File Created: {0} File Name: {1}", e.FullPath, e.Name)).ForeColor = Color.Green;
}
EDIT
The error gets thrown here:
using (var fileStream = File.OpenRead(e.FullPath)) --> HERE
{
BinaryReader reader = new BinaryReader(fileStream);
file = reader.ReadBytes((int)fileStream.Length);
fileStream.Close();
}
So every time I add a new file I get the above error?
Thanks