I am making an application to update my system, I download it in% temp% then I apply:
File.Copy(LocalFolderTemp + fileNameFTP, fileNameFTP,true);
But when the file is in use EXE's does not release any warning that could not be copied, it just happens. You are using this to know if it is in use:
public static bool IsFileLocked(FileInfo file)
{
FileStream stream = null;
try
{
stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None);
}
catch (IOException)
{
//the file is unavailable because it is:
//still being written to
//or being processed by another thread
//or does not exist (has already been processed)
return true;
}
finally
{
if (stream != null)
stream.Close();
}
//file is not locked
return false;
}
Which works with DOC, XLS..Etc, but nothing happens with the exe, what can be done? When the file is closed it works very well.