Solved

reading a text file from windows service

Posted on 2004-09-21
5
209 Views
Last Modified: 2010-04-17
Hi

I have developed a windows service which monitors the text file. Windows service checks the file 2 times in a second depending on the frequency it is set.

I want to know how to detect whether a new line is added or multiple lines has been added. If added then I want to read those lines.


My windows service has a timer that triggers every 2 times in a second.


any code will be highly appriciated.


Shahzad Aslam
0
Comment
Question by:shahzad73
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:deepaknet
ID: 12110425
Hi:

You can use the FileSystemWatcher in C#:

http://www.c-sharpcorner.com/3/FSWatcherMB.asp

deepak
0
 
LVL 1

Author Comment

by:shahzad73
ID: 12110538

deepak

but i want to use this in windows service while this component raises events. where will i get the event in windows service



Shahzad
0
 
LVL 15

Accepted Solution

by:
deepaknet earned 50 total points
ID: 12110607
0
 
LVL 1

Author Comment

by:shahzad73
ID: 12110742
hi deepak

can you tell me how .net can open a file for reading while it is being opened by another process.



Shahzad
0
 
LVL 15

Expert Comment

by:deepaknet
ID: 12110819
Hi Shahzad:

You do not need to open a file to check its change. The FileSystemWatcher has an event handler which

System.IO.FileSystemEventArgs e

(This has members like name of the file changed in the path being modified).
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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

739 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