Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

StreamReader problem

Status
Not open for further replies.

kettch

Programmer
Mar 5, 2001
110
US
I start out by having a streamwriter write to a memorystream. Then later on I want to retrieve the data from the memorystream. The code, in it's basic form, looks like this:

Code:
        Dim ms As New MemoryStream
        Dim sw As StreamWriter = New StreamWriter(ms)

	    //code that writes to the stream

        Dim sr As New StreamReader(ms)
        Dim tmp As String
        tmp = sr.ReadToEnd()
        sr.Close()

In debug mode, I can see that the memory stream has the right length, there should be data in it, but nothing comes out.

What could be causing this? If I need to post more of the code, I can.

Thanks
 
I havent used memorystream so I dont know if they are the same as filestream. But one thing I often succeed in doing wrong when working with streams is that i forget to set the position of the stream to the beginning after I have written/read it.

So if you have written to your memorystream and now tries to read the same stream try:
Code:
ms.Position = 0

- - - - - - - - - - - - - - - - - -
Im three apples high, Im blue, and i most certainly like that cold beer that should be every mans right after a hard days work!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top