I do this in my C# program:
File.copy(Application.StartupPath + "\Test.txt",@"c:\Test.txt");
But I get this error:
Access to the path 'c\Test.txt' is denied
It happens only in Windows 7, in Windows XP it works excellent.
I do this in my C# program:
File.copy(Application.StartupPath + "\Test.txt",@"c:\Test.txt");
But I get this error:
Access to the path 'c\Test.txt' is denied
It happens only in Windows 7, in Windows XP it works excellent.
Win 7 blocks root folder on system drive... put the file in a place you have permissions to copy.
Windows 7 don't allow to access the program folders and the root folder. You can give the Directory writer access or change the destination path to one user Folder, like the "My Documents" or an App Directory.
You can loacate this paths with Environment.GetFolderPath();
Example
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); retrurns: "C:\Users\Admin\AppData\Roaming"
Access is denied. That means you don't have access. No, really, it does.
User accounts in Windows 7 are limited (non-Administrator) by default, so your program cannot just write anywhere on the system (and that is a Good Thing (TM)). Try putting Test.txt
in another directory, for example the temp directory (ask the system where that is).
In addition to what others said try using Special Folders. and learn a little bit about Making Your Application UAC Aware
It's best to join a file & path with Path.Join
File.copy(Path.Join(Application.StartupPath, "\Test.txt"), @"c:\Test.txt");