|
-
Mar 5th, 2003, 09:20 PM
#1
Thread Starter
Member
Streamreader and shared file access
Hi,
Two different routines below doing two similar operations, I'm sure you get the 'jist'. I prefer using 'METHOD 1' as I'm going through my code trying to get away from anything that uses the visualbasic namespace.
The file 'myfile.dat' is getting accessed by another program which is constantly being updated. If I try to use method 1 I get an error as another application is using it, which is true, Method 2 works fine because of the 'OpenShare.Shared', is there an equivalent for the streamreader.
I just want to open using streamreader method a file that is being used.
Anyone?
Thanks
Wayne
Code:
'METHOD 1
Dim strBuffer As String
Dim srFile As StreamReader = File.OpenText(Application.StartupPath & "\myfile.dat")
strBuffer = srFile.ReadToEnd
Dim InfoList() As String = strBuffer.Split(Environment.NewLine)
srFile.Close()
'METHOD 2
Dim FileNum As Integer = FreeFile()
FileOpen(FileNum, Application.StartupPath & "\myfile.dat", OpenMode.Input, OpenAccess.Read, OpenShare.Shared)
ProgValue = LineInput(FileNum)
FileClose(FileNum)
-
Mar 5th, 2003, 10:06 PM
#2
VB Code:
'METHOD 1
Dim strBuffer As String
Dim fs As New IO.FileStream(IO.Path.Combine(Application.StartupPath, "myfile.dat"), IO.FileMode.Open, IO.FileAccess.ReadWrite, IO.FileShare.ReadWrite)
Dim srFile As New IO.StreamReader(fs)
strBuffer = srFile.ReadToEnd
Dim InfoList() As String = strBuffer.Split(Environment.NewLine)
srFile.Close()
-
Mar 5th, 2003, 11:01 PM
#3
Thread Starter
Member
Cheers..... That's what I was after.
Thanks
Wayne
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|