c# - Delete one line from my text file -


i have code:

using (streamwriter writer = new streamwriter("c:\\users\\hp8200\\desktop\\teste.txt")) {                 string numcont = _transaction.partyfederaltaxid;     double numenc = _transaction.billtopartyid;     double numfatura = _transaction.transdocnumber;     datetime data = _transaction.createdate;     double valor = _transaction.totalamount;     short zona = transaction.zone.zoneid;     //preçoantesdisc mal     double precoantesdisc = _transaction.totalpaymentdiscountamount;     double preconet = transaction.details.totaladvancementnetamount;     double quantidade = transaction.details.count;     double bonus = _transaction.totalpaymentdiscountamount;     string valorstr = valor.tostring(cultureinfo.invariantculture);      foreach (itemtransactiondetail detail in transaction.details)     {         var item = myapp.dsocache.itemprovider.getitem(detail.itemid, myapp.systemsettings.basecurrency);         double taxrate = myapp.dsocache.taxesprovider.gettaxratefromtaxablegroupid(detail.taxablegroupid, "prt", "con");         string barcode = item.barcode;         item = null;          writer.writeline($"{numcont};{numenc};{numfatura};{data.tostring("dd/mm/yyyy")};{valorstr};{zona};{environment.newline}{barcode};{taxrate};{precoantesdisc};{preconet};{quantidade};{bonus}");     }  } messagebox.show("gravou"); 

it writes variables text file. when add 2 or more items it, text repeat first line. need delete first line on third line. (by first , second line, mean until {environment.newline}). possible?

you in full control of duplicated line, should fix that instead of going , trying remove result:

writer.writeline($"{numcont};{numenc};{numfatura};{data:dd/mm/yyyy)};{valorstr};{zona};"); foreach (itemtransactiondetail detail in transaction.details) {     var item = myapp.dsocache.itemprovider.getitem(detail.itemid, myapp.systemsettings.basecurrency);     double taxrate = myapp.dsocache.taxesprovider.gettaxratefromtaxablegroupid(detail.taxablegroupid, "prt", "con");     string barcode = item.barcode;     //item = null;  //not necessary - gc take care of      writer.writeline($"{barcode};{taxrate};{precoantesdisc};{preconet};{quantidade};{bonus}"); } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -