Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# database file Text read
Hi all,
i have a receiver windows application which receives stream from a port (Logical port) on which my clients is sending me some feed.
my receiver receives the feed and write it in to a text file.
 
I have an other application which reads the text file parse it and dump it in to mysql database.
 
if for some reasons if i have to stop (close) my application which dumps data in to database and restart it. after restarting the application i want to read the text file where i left it while reading it before.
i mean to say that if i have read 100 lines from text file out of 1000 and for some reasons i have to close my application.
now i start my application again and want to start from 101 line.
 
bellow is the text file format
 
"31/07/12 11:31:18","GOLD-OC12","","TRD","","",""
 
"31/07/12 11:31:18","GOLD-OC12","","ORD","49433","50","49485","50","",""
 
"31/07/12 11:31:18","GOLD-OC12","","TRD","","",""
 
"31/07/12 11:31:18","GOLD-OC12","","ORD","49435","50","49485","50","",""
 
"31/07/12 11:31:18","GOLDKILO-OC12","","TRD","","",""
 
"31/07/12 11:31:18","GOLDKILO-OC12","","ORD","49403","5","49454","5","",""
 
"31/07/12 11:31:18","GOLDKILO-OC12","","TRD","","",""
 
"31/07/12 11:31:18","GOLDKILO-OC12","","ORD","49405","5","49454","5","",""
 
"31/07/12 11:31:18","GO100OZ-OC12","","TRD","1622.5","1","5"
 
"31/07/12 11:31:18","GO100OZ-C12","","ORD","1622.4","50","1622.8","50","1622.5","1"
 
"31/07/12 11:31:18","GO100OZ-OC12","","TRD","1622.5","1","5"
 
"31/07/12 11:31:18","GO100OZ-C12","","ORD","1622.4","50","1622.8","50","1622.5","1"
Posted 11-Aug-12 3:28am
Edited 11-Aug-12 11:24am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
We are not sure how your application is working, but making some assumption i am giving you one solution.
 
Assumptions
1) each text file have single log entry
2) you have single text file having all data.
Note : even other solutions are possible if above assumptions are incorrect.
 
Solution
- You can check your database table records and go directly on that line and start reading. Let me know if you have problem with reading text file from particular position.
 
ex : you have 100 records in your database then read your text file from 101 and your application will again dump data in database.
 
hope it works for you, Let me know if you have any query.
 
Thanks
-Amit Gajjar
  Permalink  
Comments
Farhan Qureshi at 16-Aug-12 3:42am
   
yes i have single text file and at the day end the size of text file is around 250 to 350 mb
 
and please help me with example of reading text file from particular position
@amitgajjar at 16-Aug-12 4:12am
   
then proposed solution will work for you.
Farhan Qureshi at 16-Aug-12 5:45am
   
YES
but need example
reading text file from particular position.
@amitgajjar at 16-Aug-12 6:47am
   
http://stackoverflow.com/questions/1262965/c-how-do-i-read-a-specified-line-in-a-text-file
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

you mean to save last line no. some where and when application start retrieve that line no.,
read text file's lines on by one and nothing to do till counter reaches the line no. means if counter>= line_no then add entries in database
 
you can store Line-no three ways.
1. In database
2. In global application user-defined property (settings.designer.vb page)
3. In Registry key.
 
do not forget to increase line-no and update it's status in (database or global application user-defined property or registry key - any of source you used) when you have processed the line.
 
Happy Coding!
Smile | :)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 329
1 Maciej Los 290
2 Sergey Alexandrovich Kryukov 230
3 Shweta N Mishra 185
4 PIEBALDconsult 149
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 11 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100