473,387 Members | 1,890 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,387 software developers and data experts.

Bug in StreamReader?

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 to open the file in writemode which is then
denied an an exception occures.
Jul 21 '05 #1
4 1555
Hi Cody,

Change your StreamReader constructor to

StreamReader sr = new StreamReader(File.OpenRead(path));

If you also need to save data to the file, you could store all data in
memory while processing and try to obtain write access later.

--
Happy Coding!
Morten Wennevik [C# MVP]
Jul 21 '05 #2
> Change your StreamReader constructor to

StreamReader sr = new StreamReader(File.OpenRead(path));

If you also need to save data to the file, you could store all data in
memory while processing and try to obtain write access later.


Yes this would certainly solve the problem but it is really a bug in the
StreamReaderclass, is it? Iam using the following ctor:
StreamReader(string,Encoding).
Jul 21 '05 #3
Well, there is nothing in the documentations saying that it opens a file
as read only, so the name StreamReader may be misleading, and in fact, the
'path' may not even lead to a conventional file.
I would not say it was a bug, though it may have been unintentional, or
intentional as maybe having it read only as default may cause other
problems.

On Thu, 17 Mar 2005 14:15:10 +0100, cody <de********@gmx.de> wrote:
Change your StreamReader constructor to

StreamReader sr = new StreamReader(File.OpenRead(path));

If you also need to save data to the file, you could store all data in
memory while processing and try to obtain write access later.


Yes this would certainly solve the problem but it is really a bug in the
StreamReaderclass, is it? Iam using the following ctor:
StreamReader(string,Encoding).


--
Happy Coding!
Morten Wennevik [C# MVP]
Jul 21 '05 #4
> Well, there is nothing in the documentations saying that it opens a file
as read only, so the name StreamReader may be misleading, and in fact, the
'path' may not even lead to a conventional file.
I would not say it was a bug, though it may have been unintentional, or
intentional as maybe having it read only as default may cause other
problems.


Which other problems? It is a *reader*, which problems could be caused it I
have readoly access to the file?
Jul 21 '05 #5

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

Similar topics

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...
11
by: Tiger | last post by:
We can use seek() in the FileStream class,as we know. But I found that seek() is not work correctly in StreamReader. Who can tell me how to use seek() correctly in StreamReader? thanks a lot! I...
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: Mika M | last post by:
Hello! I'm reading text file line by line using the StreamReader like code below shows. Reading is working fine, but if readed line contains Scandinavian letters like äÄöÖ then those letters are...
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
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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,...

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.