我写了一个可以打开文件对话框的函数,但它不会返回文件路径+文件名。
我错过了什么?
private void browseButton_Click(object sender, EventArgs e)
{
browseDatabase(accessDatabaseTextbox.Text, "mdb bestanden|*.mdb");
}
private void browsebutton2_Click(object sender, EventArgs e)
{
browseDatabase(klantenDatabaseTextbox.Text, "accdb bestanden|*.accdb");
}
private void browseDatabase(string textbox, string filter)
{
openFileDialogDB.Filter = filter;
if (openFileDialogDB.ShowDialog() == DialogResult.OK)
{
string DBfile = openFileDialogDB.FileName;
if (System.IO.File.Exists(DBfile))
{
textbox = DBfile;
}
else
{
MessageBox.Show("Selected file doesn't exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("No file selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}