Solved

StreamReader reading appended lines

Posted on 2004-09-22
7
285 Views
Last Modified: 2010-04-15
I have a windows service that read text from a file when this is created and insert that data into a SQL DB. There is no problem to do this. With a fileSystemWatcher I have resolved this.

Then this file is modified appending new data, and there is the problem. With the onchanged event I detect when this file is modified but, ¿is there any way to only read the new lines appended?

If I read all the file I create duplicated rows in the Sql and this way is not valid.

Thanks
0
Comment
Question by:EM77
7 Comments
 
LVL 4

Accepted Solution

by:
somnatic earned 32 total points
ID: 12121518
* Why not delete the rows passed to the DB from the file .. ?

* Store the number of the last row somewhere and then read from that row on only ..
0
 
LVL 10

Assisted Solution

by:123654789987
123654789987 earned 31 total points
ID: 12121980
Instead of appending the lines to a existing file, Why don't u take a backup of this file and delete it. Then recreate the file with only the new lines. U can take a backup of the files as and when it is modified, u can append a timestamp to the backup file name this way u will know when the file was modified
0
 
LVL 18

Assisted Solution

by:armoghan
armoghan earned 31 total points
ID: 12122027
1.
If the lines are unique, you can put a check in database table of Unique rows only, and add all the rows in a batch only the new rows will be inserted and the rest will not

2.
The easiest approch would be, if you can.. Delete the file after reading the lines.

3.
Create a backup of the file and use some comparison API to compare the Files and get the changed lines only
http://www.araxis.com/merge/automation_ref.html
0
 
LVL 7

Assisted Solution

by:NipNFriar_Tuck
NipNFriar_Tuck earned 31 total points
ID: 12134188
How about getting the count of records in the DB (this would be the last line during the previous read) and looping until you get to the line after the count?  Then simply read the line and add to the db as your were doing...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expression Evaluater 3 45
C# Linq - Join two objects into one 3 31
Securing WEBAPI on Azure 2 18
orderby list (from Json) 1 27
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question