I have a form that I look for the path of a file in .mdb
(Access database), however I wanted to know how I can limit and exactly get the string of the file between the last bar of OpenFileDialog
and the point of .mdb
.
So far I've made this format:
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Database Files|*.mdb";
if (dlg.ShowDialog() == DialogResult.OK)
{
string dbfile = dlg.FileName;
label1.Text = dbfile;
string file_name = dbfile.Split('\')[5];
string first = file_name.Split('.').FirstOrDefault();
}
}
I would like it not necessary to call the last directory bar of the 5th array
(because the item could be in any folder, not necessarily in the fourth folder of the computer), but a dynamic data that could read the last one bar and .mdb
.