How to set the textreader to beginning after doing a read?

Posted on 2011-10-19
Last Modified: 2013-12-16
I have some code that uses TextReader to look for errors in the XML file before any processing.  I'm using:

                textReader.ResetState();  //  reset it...

but it doesn't seem to be setting it back to the beginning of the stream (or file).

How to fix this so I can read the TextReader from the beginning?
Question by:rmmarsh
    LVL 33

    Expert Comment

    Please try one of this:

    textReader.BaseStream.Seek(0, SeekOrigin.Begin);

    textReader.BaseStream.Position = 0;

    Author Comment

    Error      10      'System.Xml.XmlTextReader' does not contain a definition for 'BaseStream'
     and no extension method 'BaseStream' accepting a first argument of type 'System.Xml.XmlTextReader' could be found
    LVL 28

    Accepted Solution

    XmlTextReader does not provide this functionality. Here are a couple alternatives:

    Author Closing Comment

    Thank you again... I appreciate it...

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now