You can select a CSV file in C# using the OpenFileDialog class from the System.Windows.Forms namespace. Here's an example:
main.cs353 chars16 lines
The Filter
property of the OpenFileDialog
specifies that only files with extension .csv
will be visible in the dialog. The Title
property sets the title of the dialog box that appears when selecting a CSV file.
Upon selecting a valid CSV file, the FilePath
property of the OpenFileDialog
object contains the full path. StreamReader
is then used to read the contents of the selected file into memory. You can then process the data as necessary.
gistlibby LogSnag