Skip to content

Instantly share code, notes, and snippets.

@vanloc0301
Created May 26, 2016 16:01
Show Gist options
  • Save vanloc0301/a99aede16e7c525c437c7871ca17db82 to your computer and use it in GitHub Desktop.
Save vanloc0301/a99aede16e7c525c437c7871ca17db82 to your computer and use it in GitHub Desktop.
private void btnReadFileText_Click(object sender, EventArgs e)
{
lstImgExport.Clear();
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
string s = File.ReadAllText(ofd.FileName);
txtListKeyword.Text = s;
lstTextFromFile = new List<string>();
// Use using StreamReader for disposing.
using (StreamReader r = new StreamReader(ofd.FileName))
{
// Use while != null pattern for loop
string line;
while ((line = r.ReadLine()) != null)
{
lstTextFromFile.Add(line);
lstTextFromFileSplit = line.Split('-').ToList();
}
}
}
else
return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment