1
I have a form that I search the path of a file in .mdb
(Access database), however I wanted to know how I can limit and pick up exactly the string of the file between the last bar of the 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 wish it were not necessary to call the last bar of the 5th directory array
(because then 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 bar and the .mdb
.
can turn this
Console.WriteLine(fileInfo.Name);
in a variable?– MattDAVM
I will edit the example to use as a variable
– Pablo Tondolo de Vargas