title: C# WinForms - Error on OpenFileDialog MultiSelect: "Index was outside the bounds of the array."
body: <p>In debug mode, while running the C# WinFOrms App, After I select the files through the OpenFileDialog, I get the </p>
  
  <pre><code>       Error: Could not read file from disk. 
         Original error: Index was outside the bounds of the array. 
  </code></pre>
  
  <p>Do you have any idea on how to fix this Error?</p>
  
  <p>Here's my code:</p>
  
  <pre><code>    // When the user clicks on Select Files Button, this happens                
      private void sourceFiles_Click(object sender, EventArgs e)
      {
          Stream myStream;
          int i = 0;
          OpenFileDialog sourceFileOpenFileDialog = new OpenFileDialog();
  
          this.sourceFileOpenFileDialog.InitialDirectory = "i:\\CommissisionReconciliation\\Review\\";
          this.sourceFileOpenFileDialog.Filter = "Excel Files (*.xls;*.xlsx;)|*.xls;*.xlsx;|" + "All Files (*.*)|*.*";
          this.sourceFileOpenFileDialog.FilterIndex = 2;
          this.sourceFileOpenFileDialog.RestoreDirectory = true;
          this.sourceFileOpenFileDialog.Multiselect = true;
          this.sourceFileOpenFileDialog.Title = "Please Select Excel Source File(s) for Consolidation";
  
          if (this.sourceFileOpenFileDialog.ShowDialog() == DialogResult.OK)
          {
              try
              {
                  string tempFolder = System.IO.Path.GetTempPath();
  
                  foreach (string FileName in this.sourceFileOpenFileDialog.FileNames)
                  {
                      this.sourceFileOpenFileDialog.FileNames[i] = FileName;
                      listBoxSourceFiles.Items.Add(FileName);
                      Log("Source Files: " + sourceFileOpenFileDialog.FileNames[i]);
                      i++;
                      System.IO.File.Copy(FileName, tempFolder + @"\" + FileName);
                  }
              }
              catch (Exception ex)
              {
                  MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
              }
          }
  
      }
  
      //method for the sourcefileOpenFileDialog.  Do I need anything here?
      private void sourceFileOpenFileDialog_FileOk(object sender, CancelEventArgs e)
      {
  
      }
  
      //method for the listbox. Do I need anything here? 
      private void listBoxSourceFiles_SelectedIndexChanged(object sender, EventArgs e)
      {
  
      }
  </code></pre>
  
  <p>Thanks! </p>