I am probably not doing this correctly, and browsing the MSDN library hasn't helped me much. I am trying to copy my database from my project folder to another location. I initially tried the desktop, and it stated the directory was not available. This is what I currently have.
private string currentDb = @"J:\Project\Project\HotelDB.accdb",
backUpPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
newFileName = @"\";
I call it with this method. The error I currently get is that the Environment.SpecialFolder.MyDocuments class indicates that 'My Documents' is a folder, not a file. This tells me that I'm doing this all wrong. Any guidance is appreciated.
public void backupDatabase()
{
File.Copy(currentDb, backUpPath, true);
}
Definition. Copies an existing file to a new file.
Copy method takes three parameters. First the original file with full path, second the file to be copied file name with the new path and third parameter that is optional that is used to overwrite an existing file. If third parameter is true, the Copy method will overwrite if file already exists.
You should add the filename to the target path. This is clearly specified in the documentation: http://msdn.microsoft.com/en-us/library/c6cfw35a.aspx
The name of the destination file. This cannot be a directory or an existing file.
For example:
"J:\Project\Project\HotelDB.accdb"
Should go to:
"c:\HotelDB.accdb"
(And not "C:\"
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With