在我的程序中,我使用 C# 保存 Sql 备份文件,在此程序中,当我单击“SAVEDIALOG”按钮打开时,但我想将此文件保存在特定文件夹或特定路径中。
意思是,我不想让用户将此文件保存在除特定路径之外的任何地方。
请帮助我,下面是编码,我正在保存我的文件的点击事件。注意:其桌面应用程序使用 C#,SQL server 2008。
private void btnCreate_Click(object sender, EventArgs e)
{
// If there was a SQL connection created
if (srvSql != null)
{
// If the user has chosen a path where to save the backup file
if (saveBackupDialog.ShowDialog() == DialogResult.OK)
{
// Create a new backup operation
Backup bkpDatabase = new Backup();
// Set the backup type to a database backup
bkpDatabase.Action = BackupActionType.Database;
// Set the database that we want to perform a backup on
bkpDatabase.Database = cmbDatabase.SelectedItem.ToString();
// Set the backup device to a file
BackupDeviceItem bkpDevice = new BackupDeviceItem(saveBackupDialog.FileName, DeviceType.File);
// Add the backup device to the backup
bkpDatabase.Devices.Add(bkpDevice);
// Perform the backup
bkpDatabase.SqlBackup(srvSql);
}
}
else
{
// There was no connection established; probably the Connect button was not clicked
MessageBox.Show("A connection to a SQL server was not established.", "Not Connected to Server", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}