c# - Trying to update a text file -
i'm trying replace line in .txt file when click update button
this program looks http://i.imgur.com/hku4bgo.png
this code far
string[] arrline = file.readalllines("z:/daniel/sortedaccounts.txt"); arrline[accountcombobox.selectedindex] = "#1#" + firstnameinfobox.text + "#2#" + lastnameinfobox.text + "#3#" + emailinfobox.text + "#4#" + phonenumberinfobox.text + "#5#email#6#"; file.writealllines("z:/daniel/sortedaccounts.txt", arrline);
this what's inside sortedaccounts.txt
#1#bob#2#smith#3#bob@smith.com#4#5551234567#5#email#6# #1#dan#2#lastyy#3#daniel@lastyy.com#4#5551234567#5#email#6#
the combobox in order txt file.
so same index selected item in combobox. , want delete line , add new line same txt file updated information.
my code isn't doing reason though , can't figure out
try out using list remove entry @ index. don't forget reload combobox data source when file updated avoid index mismatch etc..
list<string> arrline = file.readalllines("z:/daniel/sortedaccounts.txt").tolist(); arrline.removeat(accountcombobox.selectedindex); string newline = "#1#" + firstnameinfobox.text + "#2#" + lastnameinfobox.text + "#3#" + emailinfobox.text + "#4#" + phonenumberinfobox.text + "#5#email#6#"; arrline.add(newline); file.writealllines("z:/daniel/sortedaccounts.txt", arrline);
Comments
Post a Comment