473,385 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Need to read the contents of a text file while it is open in another application for writing...

Hiya,

I need to open and read a text based log file in real time as it is being
written to by another application. Am using VB.NET in a windows forms
application.

I have attempted to use a streamreader, but get a error.

Any kick in the right direction is most appreciated!

Dave Borneman
Nov 21 '05 #1
2 1861
Which error do you get?

In any event, if the application that is writing to the file has denied
read access to other processes, then you are out of luck. If the other
application has not opened the file exclusively, then you can use a
StreamReader. Just be sure to specify the correct sharing mode when
you open the file.

Nov 21 '05 #2
As you said in real time:

If the file is being written to it will be locked for write access, so, you
will get the file is being used by another process error when trying to read
it.

You will need to have the file written to using stream writer, close it. Use
thread.sleep for a split second & then open for read access. After which
time, close it, get the thread to sleep again before opening it again.

Dim sw as New IO.StreamWriter("Your File Here With Extension")
sw.WriteLine("Your Data Here")
sw.Flush()
sw.Close
System.Threading.Thread.Sleep(200) ' 0.2 of a sec
Dim sr As New StreamReader("Your File Here With Extension")
Dim strLine As String
strLine = sr.ReadLine()
' Process your data here
sr.Close()
System.Threading.Thread.Sleep(200) ' 0.2 of a sec

Do the above in a loop & use a variable for the filename & path.

I hope this helps
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Chuck Amadi | last post by:
Sorry to bovver you again (again) here's script. I still can't see why the get_payload() doesn't produce the plain text message body of an emails in the testwwws users mailbox. As you can see I...
17
by: Guyon Morée | last post by:
what is the difference? if I open a text file in binary (rb) mode, it doesn't matter... the read() output is the same.
2
by: Matt | last post by:
Hello, In my application that I'm writing in C++ (and maybe Java), specifically the cygwin flavor of C++, I want to be able to open any existing files in FAT32 or NTFS file systems (in Windows...
1
by: cnu | last post by:
My program generates a log file for every event that happens in the program. So, I open the file and keep it open till the end. This is how I open the file for writing: <CODE> public...
1
by: Aalok | last post by:
This is what i want to do. Read a text file as an input and based on that file, Create an outpu text file which saves the contents of the input file in a specifi format in the output file. I...
5
by: ashton | last post by:
Hello, I have a file (mytest.fle) it is just a text file with a different extension. I would like to be able to open this file through my C++ application and read it in as a string. For...
66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
2
by: clintp | last post by:
In C, I'm creating a log file like this: upd = _fsopen(outputFile, "wt", _SH_DENYNO)); // writing... Here's a sample. fprintf(upd, "Sample contents"); fclose(upd);
2
kamill
by: kamill | last post by:
i need to write content of one text file into another text file. My code is working ,if i choose both files from same directory where my program reside..BUT,its not working if i select files from...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.