user5347596
user5347596

Reputation:

How do I get selected database name from Combo box in a text box when I choose the Path name

enter image description here

I want to get the database name from Database Selection when I select the path in Database Backup... For E.g: I selected the name of database name 'Sample' and then I click Browse button and choose the Path where I want to backup... Now, I want the selected database name Sample after the Location... For Instance: C:\Users\Abc\Desktop\Sample... Help to me to get the selected name of database in a text box.

Code for Browse button of Backup:

private void btnBrowseBa_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dlg = new FolderBrowserDialog();
            if(dlg.ShowDialog()== DialogResult.OK)
            {
                txtLocBa.Text = dlg.SelectedPath;
            }
        }

Upvotes: 2

Views: 151

Answers (4)

Stuart
Stuart

Reputation: 764

Try this which will get the path:

path = Path.Combine(backupPath, databaseNameComboBox.Text);

Upvotes: 0

Reza Aghaei
Reza Aghaei

Reputation: 125277

FolderBrowserDialog dlg = new FolderBrowserDialog();
if(dlg.ShowDialog()== DialogResult.OK)
{
    var database = yourDatabaseComboBox.SelectedItem.ToString();
    var extension= "bak";
    var databaseFileName = string.Format("{0}.{1}", database, extension);
    txtLocBa.Text = System.IO.Path.Combine(dlg.SelectedPath, databaseFileName);
}

Upvotes: 1

Just Do It
Just Do It

Reputation: 486

Just concatenate:

txtLocBa.Text = dlg.SelectedPath + @"\" + comboBox1.Text

Upvotes: 0

cyi
cyi

Reputation: 96

Well, depending on what your combobox's name is:

private void btnBrowseBa_Click(object sender, EventArgs e)
{
    string path = "";
    FolderBrowserDialog dlg = new FolderBrowserDialog();
    if(dlg.ShowDialog()== DialogResult.OK)
    {
        path = Path.Combine(dlg.SelectedPath, comboBox.Text);
    }
}

Upvotes: 0

Related Questions