I am making a program in which the user needs to load in multiple files. However, in the ListBox
I need to show only file names of the files they loaded but still be able to use the files loaded. So I want to hide the full path. This is how I load a file into the ListBox
now, but it shows the whole path:
private void browseBttn_Click(object sender, EventArgs e)
{
OpenFileDialog OpenFileDialog1 = new OpenFileDialog();
OpenFileDialog1.Multiselect = true;
OpenFileDialog1.Filter = "DLL Files|*.dll";
OpenFileDialog1.Title = "Select a Dll File";
if (OpenFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
dllList.Items.AddRange(OpenFileDialog1.FileNames);
}
}
You can extract the
fileName
of the absolute path using thestatic Class Path
in theSystem.IO namespace