Question

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

mySaveFileDialog.FileName = "Backup Database " + dateTimeNow;
if (mySaveFileDialog.ShowDialog() == DialogResult.OK) 
{
    string fileAsal = System.IO.Path.Combine(Global.myDatabaseLocation, "data.mdb");
    System.IO.File.Copy(fileAsal, mySaveFileDialog.FileName, true);
}

the problem is i wanna create a folder let's say 'myBackup' which contain all backup file (db, image,movie) this is as far as I can

mySaveFileDialog.FileName = "Backup Database " + dateTimeNow;
if (mySaveFileDialog.ShowDialog() == DialogResult.OK)
{
    string pathDestination = "C:\\Users\\Maju\\Desktop\\";
    string nameFolder = "myBackup";
    string fileAsal = System.IO.Path.Combine(Global.myDatabaseLocation, "data.mdb");

    System.IO.Directory.CreateDirectory(@pathDestination + nameFolder);
    System.IO.File.Copy(fileAsal, mySaveFileDialog.FileName, true);
}

I can't get where is user wanna placed backup file (pathDestination)
any idea how to do it?

Était-ce utile?

La solution

The mySaveFileDialog.FileName contains User wanna placed backup file path. you can use FileInfo to get it.

FileInfo fi = new FileInfo(mySaveFileDialog.FileName);

\\Then you can use the properties of the FileInfo object to retrieve the
\\information you want:

fi.DirectoryName \\ the directory's full path

Autres conseils

just use FileDialog.InitialDirectory

 mySaveFileDialog.FileName = "Backup Database " + dateTimeNow;
 if (mySaveFileDialog.ShowDialog() == DialogResult.OK)
        {
            string pathDestination = mySaveFileDialog.InitialDirectory;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top