473,663 Members | 2,743 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1877
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("Y our Data Here")
sw.Flush()
sw.Close
System.Threadin g.Thread.Sleep( 200) ' 0.2 of a sec
Dim sr As New StreamReader("Y our File Here With Extension")
Dim strLine As String
strLine = sr.ReadLine()
' Process your data here
sr.Close()
System.Threadin g.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
6973
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 have tried a few things but no joy what am I missing. Is the another snippet in relation to get_payload to access the body contents print and process to a file. Cheers
17
10471
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
3023
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 XP) for read-only purposes. In particular, I want my program to unconditionally be able to read-only open any file--and be able to read all the contents from said fail--which has been marked with any sort of "exclusionary" lock, including write...
1
6739
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 CLogHandler() { this.m_fsLog = new FileStream(strTodaysLogFile, System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.Read); this.m_swLog = new StreamWriter(this.m_fsLog);
1
1840
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 know how to read a text file and i can even display the contents o the input file on the prompt. However i am trying to figure out how t save the contents of the input file in a specific manner.
5
1411
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 example, I would right click on this file, select open with, then navigate to my EXE to open this file.
66
5338
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 occurs. After the program has read the file, it should offer a menu with three choices. the first is to list all the words along with the number of occurences. The second is to let you enter a word, with the program reporting how many times the...
2
10778
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
2588
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 out of that directory(where my application reside). how can i overcome to it. my code is this.. Form to select two files <form method="post" action="" enctype="multipart/form-data">
0
8436
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8771
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8548
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8634
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5657
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4182
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2000
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.