Solved

StreamReader reading appended lines

Posted on 2004-09-22
7
284 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 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