Question delete records?

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,272
Location
Sydney, Australia
Programming Experience
10+
You can't actually delete anything from a text file. You need to read the existing data in and then write the new data out. If you use a temporary file then you can read and write one record at a time, then move the temp file to overwrite the original. Otherwise, you would need to read the records into some sort of collection, remove the records to be deleted and then write the collection back out to the file.
 

stephen

New member
Joined
Jun 23, 2013
Messages
3
Programming Experience
Beginner
You can't actually delete anything from a text file. You need to read the existing data in and then write the new data out. If you use a temporary file then you can read and write one record at a time, then move the temp file to overwrite the original. Otherwise, you would need to read the records into some sort of collection, remove the records to be deleted and then write the collection back out to the file.

pls i need a practical Approach to this
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,272
Location
Sydney, Australia
Programming Experience
10+
I've already given you a practical approach. If what you actually mean is that you want someone to write the code for you, how about you show us what you've done so far? We don't know anything about your data or how you might be reading it currently. If you don't know how to read your data from the text file then maybe you should have addressed that before worrying about how to delete it. If you do know how to read the data in then stop keeping it a secret and show us. Once we know what form the data is in after you've read it, then we can tell you how to delete records from that data specifically.
 
Top Bottom