Kasun Lee

Kasun Lee

  • NA
  • 178
  • 14.1k

File.Copy() causes an I.O exception.

Oct 1 2022 12:46 PM

Hi!

I'm trying to do a file-copy operation using the paths I get from enumerated processes. It works OK when I debug the program, adding a breakpoint at line-5 and stepping into the Copy method. But when I run it directly in VStudio or by double-clicking the exe, it gives an "System.IO.IOException" excetion. Anyone knows why?

if (MessageBox.Show("You Sure?", "!!", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
 exePath = proc.MainModule.FileName.ToString();
 proc.Kill();
 File.Copy(Application.ExecutablePath, exePath, true);
}
                            }

 

Thanks!


Answers (4)