Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8825233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:49:44+00:00 2026-06-14T06:49:44+00:00

I am using streamreader in C# and my goal is to read a text

  • 0

I am using streamreader in C# and my goal is to read a text file with it and it must filter out text between the tags (like <Test> </Test> or <Name> </Name> )
And get the name of the tag like ( Test or Name) then save it to a string with the tag name for use later.
I have searched the internet for a few days now but cant find anything, and i dont have much experience with C# but hope there is some one who can help me.
The file itself is a .txt file

here is the code i have until now :

class Program
    {
        static void Main(string[] args)
        {

            using (StreamReader sr = new StreamReader(@"C:\testfile.txt"))
            {

                String line;
                // Read line by line
                while ((line = sr.ReadLine()) != null)
                {
                    Console.WriteLine(line);

                }
            }
            Console.ReadKey();
        }

    }

expected output is for example a string with name = everything between the name tag in plain text then test = everyting between the test tags in plain text.
sorry for my bad english but i hope there is some one who can helpe me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:49:44+00:00Added an answer on June 14, 2026 at 6:49 am

    You can use XmlDocument

            XmlDocument Info_Document = new XmlDocument();
            Info_Document.Load(@"D:\saraxml.txt");
            XmlNodeList xmlnodelist = Info_Document.GetElementsByTagName("Name");//finding all nodes called "Name"
                foreach (XmlNode c in xmlnodelist)
                {
                   string _name=c.InnerText;
                }
    

    for this file :

    <test>
    <Name> h0</Name>
    
    <Name> h1</Name>
    
    <Name> h2</Name>
    
    <Name> h3</Name>
    
    <Name> h4</Name>
    
    <Name> h5</Name>
    </test>
    

    I got:

    h0

    h1

    h2

    h3

    h4

    h5

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I read an embedded resource (text file) using StreamReader and return it
If I read and wrote a binary file using StreamReader and StreamWriter, can the
I am reading in from a text file using StreamReader into a string array
I'm using streamreader now to read a file of people names, it is a
Morning, I'm trying to split a large text file (15,000,000 rows) using StreamReader/StreamWriter. Is
I will read a file from my computer using StreamReader sr = new StreamReader(FileName);
My Code goes like this: using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream())) { string resultString
im trying to open a file using StreamReader and ive to set a Encoding,
How do you specify where to start reading in a file when using StreamReader?
The StreamReader locks a text file whilst it is reading it. Can I force

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.