I am playing a *.mp4
file in media player but at the same time trying to move the file from one place to another I need to check if the file is being accessed by another process i want to block the move process.
public Boolean fileInUse(FileInfo file)
{
FileStream stream=null;
try
{
stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None);
}
catch (IOException)
{
//File is in use
Console.WriteLine("File is Being used");
return true;
}
finally {
if (stream != null) {
stream.Close();
}
}
Console.WriteLine("File is not in use");
return false;
}