Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OpenFileDialog loadList = new OpenFileDialog();
- /// what files to open
- loadList.Filter = "Text Files (.txt)|*.txt|All Files (*.*)|*.*";
- loadList.FilterIndex = 1;
- /// multi select, is false.
- loadList.Multiselect = false;
- // open filedialog
- loadList.ShowDialog();
- /// read lines from the file
- FileStream filereader;
- try
- {
- filereader = new FileStream(loadList.FileName, FileMode.Open);
- }
- catch (IOException)
- {
- MessageBox.Show("Please exit the file before loading it!");
- return;
- }
- byte[] textbuffer = new byte[filereader.Length];
- filereader.Read(textbuffer, 0, textbuffer.Length);
- for (int i = 0; i < textbuffer.Length; i++)
- {
- //// 13 + 10 represents end of line ( char val )
- if (textbuffer[i] == 13)
- {
- if (i + 1 < textbuffer.Length && textbuffer[i + 1] == 10)
- {
- linesread++;
- }
- }
- }
- /// here you'll actually read the lines
- StringReader read = new StringReader(Encoding.ASCII.GetString(textbuffer));
- for (int i = 0; i <= linesread; i++)
- {
- ListViewItem item = new ListViewItem();
- item.Text = read.ReadLine();
- if (item.Text.Length != 0)
- {
- listView1.Items.Add(item);
- }
- }
- read.Close();
- filereader.Dispose();
- filereader.Close();
- listView1.Refresh();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement