Kasun Lee

Kasun Lee

  • 2.1k
  • 178
  • 12.3k

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

Oct 1 2022 12:46 PM


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();
 File.Copy(Application.ExecutablePath, exePath, true);



Answers (4)