Stefan Andjelovic
Stefan Andjelovic

Reputation: 1

Adding files from specific locations and adding them to listbox

I would like to code a function to which opens a file location, for eg. C:\Users\User from which I can add an MP3 file, and add it to listbox. I've tried this but it doesn't open the folder i want. Any ideas?

OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Multiselect = true;
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
    files = openFileDialog1.SafeFileNames;
    paths = openFileDialog1.FileNames;
    for (int i = 0; i < files.Length; i++)
    {
        listBox1.Items.Add(files[i]);
    }
}

Upvotes: 0

Views: 55

Answers (2)

BionicCode
BionicCode

Reputation: 28948

Setting the InitialDirectory property of the OpenFileDialog, will set the start up folder.

Upvotes: 0

NDJ
NDJ

Reputation: 5194

set the initial directory:

openFileDialog1.InitialDirectory = @"C:\Users\User";

Upvotes: 2

Related Questions