1

I have a multi-select OpenFileDialog box (named GetFiles) that loops through all the selected files and displays their path in a listbox. Problem is, when all the files are selected and added, it displays the same filename. Here is all the code:

if (GetFile.ShowDialog() == DialogResult.OK)
     foreach (string filename in GetFile.FileNames)
     {
          FileNameList.Items.Add(GetFile.FileName);       
     }

I feel like there is something really simple that I'm missing....any help will be greatly appreciated

4

2 回答 2

3

是的,您每次使用GetFile.FileName. 你需要使用你的变量filename

if (GetFile.ShowDialog() == DialogResult.OK)
 foreach (string filename in GetFile.FileNames)
 {
      FileNameList.Items.Add(filename);       
 }
于 2013-09-08T20:49:17.213 回答
1

是的,您GetFile.FileName在添加到列表而不是枚举值时使用filename

试试这个:

if (GetFile.ShowDialog() == DialogResult.OK) {
    foreach (string filename in GetFile.FileNames) {
        FileNameList.Items.Add(filename);       
    }
}
于 2013-09-08T20:49:10.077 回答