General information
Title:
Does StreamReader open file readonly?
Unexpectedly I realized that plain
Dim lcDataText As New System.IO.StreamReader(“path\text_file.txt”)
opens file exclusively preventing access to this file from another independent application.
Another independent application (VFP9) uses code like:
rst_DTW = CreateObject("ADODB.Recordset")
rst_DTW.Open("select * from " + lcfile , cnnText, adOpenStatic, adLockReadOnly)
And if this (another) process opens the file first then the first process can also work with the file.
So far I tried to follow several examples, but with no luck.
1. Setting file attributes to READONLY.
2.
Dim lcDataText As System.IO.StreamReader = System.IO.File.OpenText(lcfilename)
3. Dim fs1 As System.IO.FileStream = New System.IO.FileStream(lcfilename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)
Dim lcDataText As New System.IO.StreamReader(fs1)
Here in #3 when adding System.IO.FileShare.Read a note message pops up saying
“… However, even if this flag is specified, additional permissions might still be needed to access the file.” Probably I am falling under this “additional permissions” category, but what are they, and how to set them properly?
In addition, in another separate application I can use the following with no problem:
CREATE CURSOR yy (lcrec c(200))
Append from (lcfile) sdf
Looks like it is an evidence that something should be set for ADO recordset or connection.
Any recommendations are welcome.
Thanks
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only