I have an application that must check a folder and read any files that are copied into it. How do I test if a file in that folder is currently being written to? I only want
The only thing I can think of is that a file lock will be put on the file while it is being written to, therefore preventing you from writing to it (throwing a System.IO exception of file being locked by another process), but this is not foolproof. For example, the file could be written to in chunks by opening and closing the file for each chunk.
So you could do this with a try/catch block:
try
{
//opening the file
}
catch(IOException ex)
{
// file is open by another process
}