c# - How can I send f to LoadDataFromXml? -
this current code. how can send f loaddatafromxml ? i'm trying load , read multiple xml files 1 directory.
public form1() { this.initializecomponent(); this.initializelistview(); this.height = screen.primaryscreen.workingarea.height; var files = directory.getfiles(@"c:\games\", "*.xml").select(f => new listviewitem(f)).toarray(); listview.items.addrange(files); foreach (var f in files) { this.loaddatafromxml(f); } } private void loaddatafromxml(//what need enter here?) { xdocument document = xdocument.load(xmlfile); // how replace ? foreach (xelement gameelement in f.root.elements("game")) { string gamename = gameelement.element("gamename").value; string launchpath = gameelement.element("launchpath").value; string portablesave = gameelement.element("portablesave").value; string publisher = gameelement.element("publisher").value; string gameid = gameelement.element("gameid").value; string update = gameelement.element("update").value; // check if gameelement.element(elementname) not null game game = new game(gamename, launchpath, portablesave, publisher, gameid, update); addgametolistview(game); } }
your linq expression create listviewitem each filenames matched,
change code to
var files = directory.getfiles(@"c:\games\", "*.xml").select(f => new listviewitem(f)).toarray(); listview.items.addrange(files); foreach (listviewitem f in files) { this.loaddatafromxml(f); }
and of course receive listviewitem in loaddatafromxml method
private void loaddatafromxml(listviewitem lvi) { xdocument document = xdocument.load(lvi.text); .... }
Comments
Post a Comment