Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Asp.Net Programming

Re-reading a Stream without reopening


Anyone have any idea how I can do the following?
I have a connection to an XML file on a site I do not control, getting
a string representation of the xml data that I can then feed to my
XmlDataSource object (CurrentXMLData):
                Stream newStream =
myWebClient.OpenRead(myStringWebResource);
                TextReader newReader = new StreamReader(newStream);
                string newData = newReader.ReadToEnd();
                CurrentXMLData.Data = newData;

Now, I want to use the stream above as an argument for another method
- but the stream is at the end and doesn't support seeking.
                SReader SReader = new SFileReader(newStream); //
EndOfStream is true! so object never initializes.
The SFileReader object will support any inputs that ReadXml on a
dataset will support (XmlReader, TextReader, string filename and
Stream)
The TextReader and XmlReader don't support seeking either.
The only way I've found to do this is to re-open the stream and re-
read - which is very time consuming.

Any ideas on how I can re-use the data in CurrentXMLData, newData or
newStream to populate my SFileReader object?
Thanks in advance,
Ted

T Driver,

You can reset the stream position with the following line of code:

    newStream.Seek(0, SeekOrigin.Begin)

Hope this helps,

Steve

"T Driver" <drive@gmail.com> wrote in message

news:1181060530.393212.115910@o5g2000hsb.googlegroups.com...

On Jun 5, 10:47 am, "PlatinumBay" <stevan@community.nospam> wrote:

> T Driver,

> You can reset the stream position with the following line of code:

>     newStream.Seek(0, SeekOrigin.Begin)

> Hope this helps,

> Steve

> "T Driver" <drive@gmail.com> wrote in message

Actually, that was the first thing I tried, but for this stream (it's
not coming from a file) the stream does not support seeking (CanSeek =
false), so this doesn't work.

-----------------------------------------------Reply-----------------------------------------------
Ok, fair enough.  In that case, MSDN states:

If a class derived from Stream does not support seeking, calls to Length,
SetLength, Position, and Seek throw a NotSupportedException.

You may want to use a different stream reader (such as the MemoryStream)
that supports seeking.

Hope this helps,

Steve

"T Driver" <drive@gmail.com> wrote in message

news:1181063026.848778.161910@p77g2000hsh.googlegroups.com...

On Jun 5, 11:13 am, "PlatinumBay" <stevan@community.nospam> wrote:

Thanks - I thought of those, but hadn't had time to implement yet.  I
was hoping there would be something similar to Java's StringStream
class - this would be perfect here

-----------------------------------------------Reply-----------------------------------------------
T,

Maybe I should take a step back here, what is it that you are trying to
accomplish?

Steve

"T Driver" <drive@gmail.com> wrote in message

news:1181060530.393212.115910@o5g2000hsb.googlegroups.com...

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc