私のプログラムでは、C#を使用してSqlバックアップファイルを保存しています。このプログラムでは、ボタン「SAVEDIALOG」をクリックすると開きますが、このファイルを特定のフォルダーまたは特定のパスに保存したいです。
つまり、ユーザーがこのファイルを特定のパス以外の場所に保存できるようにしたくありません。
親切に助けてください。以下はコーディングで、クリックイベントでファイルを保存しています。注記: C#、SQL サーバー 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);
}
}