Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Does StreamReader open file readonly?
Message
 
To
All
General information
Forum:
ASP.NET
Category:
Other
Title:
Does StreamReader open file readonly?
Environment versions
Environment:
VB 8.0
Miscellaneous
Thread ID:
01434675
Message ID:
01434675
Views:
171
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
Map
View

Click here to load this message in the networking platform