c# - Looping trough textbox controls in a panel control -
c# - Looping trough textbox controls in a panel control -
i'm trying create csv order details pull textboxes. have panel command has 12 textboxes sitting within , want write text of each textbox onto new line in csv nil happening, file gets created no text.
here's code:
filestream file = new filestream(string.format(@"z:\stream\order{0}.csv", txtname.text),filemode.openorcreate); streamwriter wr = new streamwriter(file); wr.writeline(txtname.text); wr.writeline(txtorderref.text); list<textbox> textboxcontrols = new list<textbox>(); foreach (textbox controls in panel1.controls) { textboxcontrols.add(controls); } foreach(textbox c in textboxcontrols) { wr.writeline(c.text); label1.text = c.text + "<br />"; } wr.close();
thanks
i'd imagine problem lies in closing of stream, should utilize using
block
using(streamwriter wr = new streamwriter(file)) { wr.writeline(txtname.text); wr.writeline(txtorderref.text); foreach (var command in panel1.controls.oftype<textbox>()) { wr.writeline(control.text); } }
c# asp.net stream
Comments
Post a Comment