【问题标题】:Add multiple FilePaths from OpenFileDialog to List<>将 OpenFileDialog 中的多个 FilePaths 添加到 List<>
【发布时间】:2023-01-20 21:04:50
【问题描述】:

我目前正在尝试将我通过 OpenFileDialog 选择的图片的所有文件路径添加到 List<>。但是,当我尝试启动程序时,只有第一个文件的路径被多次添加到列表中。

这是我试过的代码

            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))));
                }

            }

【问题讨论】:

  • 使用:string fullPath = file;

标签: c# .net path openfiledialog


【解决方案1】:

你必须这样做。您正在使用 MyDialog.FileName 而不是您应该使用 file

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

【讨论】:

    猜你喜欢
    • 2021-03-12
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    • 1970-01-01
    • 2018-07-17
    • 2014-04-14
    • 1970-01-01
    • 2022-12-17
    相关资源
    最近更新 更多