Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
i'm using stream reading and writing for file handling in c#. but getting this error.


C#
Paste code snippet here


What I have tried:

i have used stream.close() everywhere where i have used streaming in my whole program's functions of classes.
Posted
Updated 15-May-17 5:52am
v3
Comments
[no name] 15-May-17 11:33am    
Okay then you should probably look at your code, find out why it's failing, then fix your code.
Dave Kreskowiak 15-May-17 11:37am    
Ummm...without knowing anything about your code, specifically where this is failing, we really can't help you. It would help immensely if you could show that. Hit the "Improve question" link and add the code.
Fahad Iftikhar 15-May-17 11:41am    
lols. i've posted my whole code here, just copy and paste kindly and check it. thanks :)
Dave Kreskowiak 15-May-17 11:47am    
No, that's not how this works. YOU debug the code, we help. We're not in the business of doing your job or your homework for you.

I'm not running the entire thing. You just need to post the relevant part that fails.
Fahad Iftikhar 15-May-17 13:03pm    
oh Okay. i'm sorry, newbie here.

Dumping your code on us like that is rude: in future only give us the relevant fragment - the method the error occurs in at most.

But...look at your code:
C#
FileStream fs = new FileStream(fileName, FileMode.Append, FileAccess.Write, FileShare.None);
StreamReader sr = new StreamReader(fs);
When you open a file for Append, you can;t read it: FileMode Enumeration (System.IO)[^]:
Quote:
Opens the file if it exists and seeks to the end of the file, or creates a new file. This requires FileIOPermissionAccess.Append permission. FileMode.Append can be used only in conjunction with FileAccess.Write. Trying to seek to a position before the end of the file throws an IOException exception, and any attempt to read fails and throws a NotSupportedException exception.
If you want to read the file, open it for Read, not Append or Write.
 
Share this answer
 
Guessing as it seems to appear alot when googled you are trying to access the read stream after it has been disposed. But it is a guess as you haven't posted a code snippet.


c# - Stream was not readable error - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900