473,404 Members | 2,114 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,404 software developers and data experts.

StreamReader (ReadOnly)

Greetings!

I'm opening a text file with as a StreamReader. The problem is when the file
is used by another user or Windows, it won't open! When I double click the
file it opens it. That's strange. Shouldn't it open it as read-only? Is
there an option to force it to open the file?

I'm using:
Dim sr As New StreamReader("C:\myfile.txt")

what if I use:
Dim s As New Stream = File.OpenRead("C:\myfile.txt")
Dim sr As New StreamReader(s)

would that work??
My final option is copying the file to a temp directory and open it from
there.
Nov 21 '05 #1
1 9846
Answer provided by Herfried Wagner....

* "Cor Ligthert" <no**********@planet.nl> scripsit:
Did you send this with a reason to the language VB group or by accident?

However a file using the streamreader/writer will be locked until it is
closed.

Not necessarily:

\\\
Dim fs1 As New System.IO.FileStream("C:\Log.txt", FileMode.Open,
FileAccess.Read, FileShare.ReadWrite)
Dim fs2 As New System.IO.FileStream("C:\Log.txt", FileMode.Open,
FileAccess.Read, FileShare.ReadWrite)
Dim sr1 As New System.IO.StreamReader(fs1)
Dim sr2 As New System.IO.StreamReader(fs2)
MsgBox(sr1.ReadLine())
MsgBox(sr2.ReadLine())
sr1.Close()
sr2.Close()
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
"Pantelis Sotiropoulos" <no@spam.please> wrote in message
news:Oh**************@TK2MSFTNGP15.phx.gbl: Greetings!

I'm opening a text file with as a StreamReader. The problem is when the
file
is used by another user or Windows, it won't open! When I double click
the
file it opens it. That's strange. Shouldn't it open it as read-only? Is
there an option to force it to open the file?

I'm using:
Dim sr As New StreamReader("C:\myfile.txt")

what if I use:
Dim s As New Stream = File.OpenRead("C:\myfile.txt")
Dim sr As New StreamReader(s)

would that work??
My final option is copying the file to a temp directory and open it from
there.


Nov 21 '05 #2

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

Similar topics

4
by: cody | last post by:
When using a StreamReader I cannot open files that are currently opened from another application and are therefore readonly. But I can open these files in notepad. It seems that StreamReader tries...
9
by: oafyuf | last post by:
Hi, I'm having performanbce issues with StreamReader and was wondering what I could do to improve it... The following takes around 3 seconds to process! The content of the response is: ...
5
by: Anders Olsson | last post by:
I need to create a StreamReader which starts from the position of an existing StreamReader. This way, the second StreamReader can read lines "ahead" in an own loop, and then I can go back to the...
2
by: Keith Kingsley | last post by:
I'm using a StreamReader to read in several lines from an ASCII file. I'd like to know the StreamReader's "true" position-- that is, the number of bytes into the file that the StreamReader has...
3
by: Arno | last post by:
Hi, I'm using TcpClient for communication between two PC running a small piece of software. The protocol used has been designed internally and is HTTP similar (command line, headers, body). A...
3
by: Arpan | last post by:
A file can be read using only the StreamReader object like this: Dim sReader As StreamReader sReader = New StreamReader(Server.MapPath("File1.txt")) While(sReader.Peek -1)...
1
by: garyusenet | last post by:
>From MSDN I'm trying to learn more about streamreader. I'm working my way down the MSDN definition. The first entry is the Public Constructor StreamReader. I'm fairly happy I have a basic grasp on...
1
by: Sladan | last post by:
Im trying to read a xml-file with a StreamReader. For the moment I'm using the following code. streamReader = new StreamReader(stream, System.Text.Encoding.Default); string feedData =...
0
by: rajana | last post by:
Dear All, We have Ansi file with german characters (Ä / Ø) , We are using Streamreader to read the contents of the file. But Readline() not able to read the German characters. We tried all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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...
0
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...

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.