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?

有帮助吗?

解决方案

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

其他提示

just use FileDialog.InitialDirectory

 mySaveFileDialog.FileName = "Backup Database " + dateTimeNow;
 if (mySaveFileDialog.ShowDialog() == DialogResult.OK)
        {
            string pathDestination = mySaveFileDialog.InitialDirectory;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top