c# - appending info to a text file -


i have web site adding records database , info writing log file part of website. info written file fine...the question have how add information each input database. @ moment information put int lof file each new insert database existing record in log file seems overwritten , replaced new insert there 1 record added log file. advice perhaps... code used in btnclick event.

protected void btnsubmitrating_click1(object sender, eventargs e) {     int rating = 0;     try     {         if (radrating.items[0].selected)         {             rating = 1;         }         if (radrating.items[1].selected)         {             rating = 2;         }         else if (radrating.items[2].selected)         {             rating = 3;         }         else if (radrating.items[3].selected)         {             rating = 4;         }         else if (radrating.items[4].selected)         {             rating = 5;         }         filestream rate = new filestream(server.mappath("~/ratebooks.log"), filemode.open, fileaccess.readwrite);         bufferedstream bs = new bufferedstream(rate);         rate.close();           streamwriter sw = new streamwriter(server.mappath("~/ratebooks.log"));         sw.writeline("username " + txtusername.text + " " + "booktitle " + txtbooktitle.text + " " + "isbn " + txtisbn.text);         sw.close();           service s = new service();         s.bookratedadd(txtbooktitle.text, rating, txtreview.text, txtisbn.text, txtusername.text);         btnsubmitrating.enabled = false;         radrating.enabled = false;                 }     catch (exception em)     {         lblerror.text = em.message;          //lblerror.text = "this book has been reviewed yourself?";     } } 

kind regards

change whole block of code:

filestream rate = new filestream(server.mappath("~/ratebooks.log"), filemode.open, fileaccess.readwrite); bufferedstream bs = new bufferedstream(rate); rate.close();  streamwriter sw = new streamwriter(server.mappath("~/ratebooks.log")); sw.writeline("username " + txtusername.text + " " + "booktitle " + txtbooktitle.text + " " + "isbn " + txtisbn.text); sw.close(); 

to single line:

file.appendalltext(server.mappath("~/ratebooks.log"), "username " + txtusername.text + " " + "booktitle " + txtbooktitle.text + " " + "isbn " + txtisbn.text + environment.newline); 

note i'm adding manually newline each line.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -