Question

i wanna create backup data in my application I used saveFileDialog, so i can place backup file anywhere i want (Dekstop, drive D, etc)

my backup file will be db, image, video so i guess it's will be easier to place that in one folder let say it's "myBackup" folder (generate automatically with C#) so if user wanna save in Dekstop all of backup data will be in ~C:\Users\Maju\Desktop\myBackup~

i already successfully generate folder but my file won't save inside that

mySaveFileDialog.FileName = "Backup Database " + dateTimeNow;

if (mySaveFileDialog.ShowDialog() == DialogResult.OK)
{
    string fileAsal = System.IO.Path.Combine(Global.myDatabaseLocation, "data.mdb");

    FileInfo fi = new FileInfo(mySaveFileDialog.FileName);
    string nameFolder = "myBackup";
    System.IO.Directory.CreateDirectory(@fi.DirectoryName + "\\" + nameFolder);

    string path = System.IO.Path.Combine (fi.DirectoryName, "\\" + nameFolder);
    string pathDestination = System.IO.Path.Combine(path, mySaveFileDialog.FileName);
    System.IO.File.Copy(fileAsal, pathDestination, true);
}
Était-ce utile?

La solution

  1. Is not it easier to use FolderBrowserDialog?
  2. mySaveFileDialog.FileName already includes the path to the file so you need to write

    string pathDestination = System.IO.Path.Combine(path, System.IO.Path.GetFileName(mySaveFileDialog.FileName));
    
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top