c# - Reading data from array and write to append to existing file:My code is not appending data as expected -
my application reads data array , writes existing file. shall write end of line, when run application not append anything.
after researching came across this similar post. modified code answered on post, receive error:
'filestream'
namespace
usedtype
.
i added system.io
namespace still problem persists.
this code:
private void button1_click(object sender, eventargs e) { string file_path = @"c:\users\myfolder\desktop\filestream\processed\output.txt"; string data = " "; try { using (filestream afile = new filestream(file_path, filemode.append, fileaccess.write)) using (streamwriter author = new streamwriter(afile, true)) { string[] output_receiptnos = readfile().toarray(); (int index = 0; index < output_receiptnos.length; index++) { data = output_receiptnos[index]; author.writeline(data); } messagebox.show("data sucessfully processed"); } } catch (exception err) { messagebox.show("could not process data"); } }
your filestream
adds nothing work of streamwriter
predefined constructor takes string (for filename) , boolean (for appending(overwrite data). , written not compilable because streamwriter
has no constructors takes stream , boolean.
as has mentioned in comments, have conflict in code namespace oddly named "filestream". (a bad idea way).
however, think remove error using directly streamwriter class.
take time find why compiler thinks have namespace named "filestream"
using (streamwriter author = new streamwriter(file_path, true)) { string[] output_receiptnos = readfile().toarray(); (int index = 0; index < output_receiptnos.length; index++) { data = output_receiptnos[index]; author.writeline(data); } messagebox.show("data sucessfully processed"); }
Comments
Post a Comment