Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using System.Windows.Forms;
- namespace CSV_Reader
- {
- public partial class Form1 : Form
- {
- List<string> listFiles = new List<string>();
- public Form1()
- {
- InitializeComponent();
- }
- private void Button1_Click(object sender, EventArgs e)
- {
- OpenDirectory();
- }
- private void OpenDirectory()
- {
- listFiles.Clear();
- listView.Items.Clear();
- using (FolderBrowserDialog fbd = new FolderBrowserDialog()
- {
- Description = "Select your path."
- })
- {
- if (fbd.ShowDialog() == DialogResult.OK)
- {
- txtPath.Text = fbd.SelectedPath;
- foreach (string item in Directory.GetFiles(fbd.SelectedPath))
- {
- FileInfo fi = new FileInfo(item);
- if (fi.FullName.Contains(".xlsx"))
- {
- imageList1.Images.Add(Icon.ExtractAssociatedIcon(item));
- listFiles.Add(fi.FullName);
- listView.Items.Add(fi.Name, imageList1.Images.Count - 1);
- }
- }
- }
- }
- }
- private void ListView_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (listView.FocusedItem != null)
- {
- ReadAllData(listFiles[listView.FocusedItem.Index]);
- }
- }
- void ReadAllData(string fileToRead)
- {
- using (var reader = new StreamReader(fileToRead))
- {
- List<string> listA = new List<string>();
- List<string> listB = new List<string>();
- while (!reader.EndOfStream)
- {
- var line = reader.ReadLine();
- var values = line.Split(',');
- foreach (string item in values)
- {
- listA.Add(item);
- }
- }
- DisplayData(listA);
- }
- }
- void DisplayData(IList<string> list)
- {
- foreach (string item in list)
- {
- MessageBox.Show(item);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement