0
votes

while click the backup btn it opened a savefiledialog box but i couldnt find .bak extension at save as type code: private void backupdb_Load(object sender, EventArgs e)
{ label4.Visible = false;

        DataSet ds = SqlGetData.GetData1("select srvname  from sysservers  where srvproduct='SQL Server'");

        for (int m = 0; m < ds.Tables[0].Rows.Count; m++)
        {
            cbserver.Items.Add(ds.Tables[0].Rows[0][m].ToString());
        }
    } 

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { cbdb.Items.Clear(); DataSet ds = SqlGetData.GetData1("select name from sysdatabases"); for (int m = 0; m < ds.Tables[0].Rows.Count; m++) { cbdb.Items.Add((ds.Tables[0].Rows[m][0].ToString()).ToString()); } }

    private void button1_Click(object sender, EventArgs e)
    {

        blank("backup");


    }

    public void blank(string str)
    {
        if (string.IsNullOrEmpty(cbserver.Text) | string.IsNullOrEmpty(cbdb.Text))
        {

            label4.Visible = true;
            MessageBox.Show("Server Name & Database can not be Blank");
            return;

        }
        else
        {
            if (str == "backup")
            {
                saveFileDialog1.FileName = cbdb.Text;
                saveFileDialog1.ShowDialog();
                string s = null;
                s = saveFileDialog1.FileName;
                saveFileDialog1.Filter = "All Files|*.bak";
                query("Backup database " + cbdb.Text + " to disk='" + s + "'");

                label4.Visible = true;
                label4.Text = "Database BackUp has been created successful";



            }
        }
1

1 Answers

0
votes

Move the line to set the filter to be before the dialog is displayed

saveFileDialog1.Filter = "All Files|*.bak"
saveFileDialog1.ShowDialog();