Created
July 12, 2012 22:22
-
-
Save ferclaverino/3101475 to your computer and use it in GitHub Desktop.
Single responsability example, step 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void btnLoad_Click(object sender, EventArgs e) | |
{ | |
listView1.Items.Clear(); | |
var fileName = txtFileName.Text; | |
using (var fs = new FileStream(fileName, FileMode.Open)) | |
{ | |
var reader = XmlReader.Create(fs); | |
while (reader.Read()) | |
{ | |
if (reader.Name != "product") continue; | |
var id = reader.GetAttribute("id"); | |
var name = reader.GetAttribute("name"); | |
var unitPrice = reader.GetAttribute("unitPrice"); | |
var discontinued = reader.GetAttribute("discontinued"); | |
var item = new ListViewItem(new string[] { id, name, unitPrice, discontinued }); | |
listView1.Items.Add(item); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment