Dim dlg = New Microsoft.Win32.OpenFileDialog()
dlg.Filter = "Excel 97-2003 Workbook (*.xls)|*.xls|" +
"Excel Workbook (*.xlsx)|*.xlsx" +
"Text File (*.txt)|*.txt|"
If dlg.ShowDialog().Value Then
Try
Using s = dlg.OpenFile()
Dim ext = System.IO.Path.GetExtension(dlg.SafeFileName).ToLower()
Select Case ext
Case ".txt"
flex.Load(s, ImportFileFormat.TXT)
Exit Select
Case ".xlsx"
flex.Load(s, ImportFileFormat.XLSX)
' ImportFileFormat uses namespace FlexGrid
Exit Select
Case ".xls"
flex.Load(s, ImportFileFormat.XLS)
Exit Select
End Select
End Using
Catch x As Exception
Dim msg = "Error opening file: " & vbCr & vbLf & vbCr & vbLf + x.Message
MessageBox.Show(msg, "Error", MessageBoxButton.OK)
End Try
End If