日期:2014-05-17 浏览次数:20921 次
最后一步复制替换的时候出现oldFile访问被拒绝,是什么原因?
Assembly oldfile = Assembly.LoadFile(oldFile);
Version oldVer = oldfile.GetName().Version;
Assembly newfile = Assembly.LoadFile(newFile);
Version newVer = newfile.GetName().Version;
if (newVer != oldVer)
{
Process[] myPro = Process.GetProcesses();
foreach (Process now in myPro)
{
if (now.ProcessName == Path.GetFileName(oldFile)) now.Kill();
}
File.Delete(oldFile);
}
File.Copy(newFile, oldFile, true);