private void Form1_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { string filepath = openFileDialog1.FileName; FileInfo file = new FileInfo(filepath); string name = file.Name; string sourceFile = @openFileDialog1.FileName; string destinationFile = @"C:\Program Files\Windows Sidebar\Gadgets\" + name; // To move a file or folder to a new location: System.IO.File.Move(sourceFile, destinationFile); } }
An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll<br /> <br /> Additional information: Access to the path is denied.
File.Move
File.Copy
Program Files
C:\Program Files
must not
private void button1_Click(object sender, EventArgs e) { OpenFileDialog ofd=new OpenFileDialog(); if (ofd.ShowDialog()==DialogResult.OK) { System.IO.File.Move(ofd.FileName, @"Your Destination Path Here"+ofd.SafeFileName); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)