Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 36975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:28:39+00:00 2026-05-10T14:28:39+00:00

I have a .csv file that is frequently updated (about 20 to 30 times

  • 0

I have a .csv file that is frequently updated (about 20 to 30 times per minute). I want to insert the newly added lines to a database as soon as they are written to the file.

The FileSystemWatcher class listens to the file system change notifications and can raise an event whenever there is a change in a specified file. The problem is that the FileSystemWatcher cannot determine exactly which lines were added or removed (as far as I know).

One way to read those lines is to save and compare the line count between changes and read the difference between the last and second last change. However, I am looking for a cleaner (perhaps more elegant) solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:28:40+00:00Added an answer on May 10, 2026 at 2:28 pm

    I’ve written something very similar. I used the FileSystemWatcher to get notifications about changes. I then used a FileStream to read the data (keeping track of my last position within the file and seeking to that before reading the new data). Then I add the read data to a buffer which automatically extracts complete lines and then outputs then to the UI.

    Note: ‘this.MoreData(..) is an event, the listener of which adds to the aforementioned buffer, and handles the complete line extraction.

    Note: As has already been mentioned, this will only work if the modifications are always additions to the file. Any deletions will cause problems.

    Hope this helps.

       public void File_Changed( object source, FileSystemEventArgs e )     {         lock ( this )         {             if ( !this.bPaused )             {                 bool bMoreData = false;                  // Read from current seek position to end of file                 byte[] bytesRead = new byte[this.iMaxBytes];                 FileStream fs = new FileStream( this.strFilename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite );                  if ( 0 == this.iPreviousSeekPos )                 {                     if ( this.bReadFromStart )                     {                         if ( null != this.BeginReadStart )                         {                             this.BeginReadStart( null, null );                         }                         this.bReadingFromStart = true;                     }                     else                     {                         if ( fs.Length > this.iMaxBytes )                         {                             this.iPreviousSeekPos = fs.Length - this.iMaxBytes;                         }                     }                 }                  this.iPreviousSeekPos = (int)fs.Seek( this.iPreviousSeekPos, SeekOrigin.Begin );                 int iNumBytes = fs.Read( bytesRead, 0, this.iMaxBytes );                 this.iPreviousSeekPos += iNumBytes;                  // If we haven't read all the data, then raise another event                 if ( this.iPreviousSeekPos < fs.Length )                 {                     bMoreData = true;                 }                  fs.Close();                  string strData = this.encoding.GetString( bytesRead );                 this.MoreData( this, strData );                  if ( bMoreData )                 {                     File_Changed( null, null );                 }                 else                 {                     if ( this.bReadingFromStart )                     {                         this.bReadingFromStart = false;                         if ( null != this.EndReadStart )                         {                             this.EndReadStart( null, null );                         }                     }                 }             }         } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 73k
  • Answers 74k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Use the -d operator and File::Path. use File::Path qw(make_path); eval… May 11, 2026 at 2:11 pm
  • added an answer That would be a Double Here's a nice cross reference. May 11, 2026 at 2:11 pm
  • added an answer What changes you need depends mostly on what queries you… May 11, 2026 at 2:11 pm

Related Questions

I have a CSV file that holds about 200,000 - 300,000 records. Most of
I have a CSV data file with rows that may have lots of columns
I have a CSV of file of data that I can load in R
I have a simple report that I want to export to a CSV file.
I have a shell script that saves the output of a command that is
I have a SSIS package that has a child package that is failing. The
Yesterday I had the need for a matrix type in Python. Apparently, a trivial

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.