c# - File contents filtering -
i'm trying develop application take data datagrid , based on drop down menu choice return csv file selected client . code shown below , links previous question posted howeever still getting no values , need sort out i'm wondering if can either see i'm going wrong or else provide alternatives
//master inventory export private void exportclass_click(object sender, eventargs e) { stringbuilder str = new stringbuilder(); objsqlcommands2 = new sqlcommands("masterinventory", "clientname"); string strstring = str.tostring(); string filepath = txtsaveshareclass.text.tostring(); str.append("isin ,fundname,status,share ccy,benchmark,nav freq,classcode,simulation,hedged,fundccy"); stringmanipulation sm = new stringmanipulation(); foreach (datarow dr in this.calcdataset.masterinventory) { foreach (object field in dr.itemarray) { str.append(field.tostring() + ","); } str.replace(",", "\n", str.length - 1, 1); } try { system.io.file.writealltext(filepath, str.tostring()); } catch (exception ex) { messagebox.show("write error :" + ex.message); } list<string[]> lsclientlist = objstringmanipulation.parsecsv(filepath,cmbclientlist .text.tochararray()); foreach (string[] laclient in lsclientlist) { sm.parsecsv2(filepath, cmbclientlist.text.tochararray()); list<string[]> newfoo = lsclientlist.where(x => x.contains(cmbclientlist.text)).tolist(); list<string[]> results = sm.parsecsv2(filepath, cmbclientlist.text.tochararray()).where(x => x.contains(cmbclientlist.text)).tolist(); //refreshs client table on display system.io.file.writealltext(filepath, results.tostring()); } this.tableadapter.fill(this.calcdataset.masterinventory); datagridview2.update(); }
if of variables filling , results
list contains data expect, problem writealltext
call. have:
system.io.file.writealltext(filepath, results.tostring());
that not going produce output seem expect. give class name.
results
list<string[]>
. if want output csv, have enumerate it:
using (var outfile = new streamwriter(filepath)) { foreach (var line in results) { stringbuilder sb = new stringbuilder(); foreach (var field in line) { sb.append(field + ","); } sb.length = sb.length -1; outfile.writeline(sb.tostring()); } }
Comments
Post a Comment