Home > OS >  Add multiple FilePaths from OpenFileDialog to List<>
Add multiple FilePaths from OpenFileDialog to List<>

Time:11-08

Im currently trying to add all the filePaths of the pictures that i selected through a OpenFileDialog to a List<>. However when i try to start the program only the path of the first file is added to the List multiple times.

This is the code i tried it with

            OpenFileDialog MyDialog = new OpenFileDialog();
            MyDialog.Filter = "Picture (.jpg)|*jpg|Picture (.jpeg)|*.jpeg|Picture (.png)|*.png";
            MyDialog.Multiselect = true;
            if (MyDialog.ShowDialog() == true)
            {
                foreach (String file in MyDialog.FileNames)
                {
                    string fullPath = MyDialog.FileName;
                    FileListe.Add(Convert.ToString(new BitmapImage(new Uri(fullPath))));
                }

            }

CodePudding user response:

you have to do it like this. you are using MyDialog.FileName instead of that ou should use file

FileListe.Add(Convert.ToString(new BitmapImage(new Uri(file ))));
  • Related