I would like ask for some advice please, I am trying to create a program in C# but have the following problem. I am currently trying to loop through a batch of XML files that are stored in a folder. However, I just don't want to loop through the XML file name, as I need to check through all the nodes in each XML file(650 files) for certain values. I know how to loop through a specific Xml file but unsure of how to actually loop through all XMl files to retrieve the values inside the values. For now, all I have is code to read through a specific XML file as shown below. I would be grateful for any assistance in this matter.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using System.Xml.Linq;

namespace VoteProg_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
      
        XmlTextReader XReader = new XmlTextReader      ("C:\\Users\\Mark\\Documents\\VoteResults2\\result001.xml");
       
         private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        
        {     

           foreach (string fileName in XFiles)
            {

                
            while (XReader.Read()) 
            {
                switch (XReader.NodeType) 
                {
                    case XmlNodeType.Element: // The node is an element.
                        textBox1.Text = XReader.Name.ToString();                        
                        break;
                    case XmlNodeType.Text: //Display the text in each element.
                        textBox1.Text = XReader.Value.ToString();
                        break;
                    case XmlNodeType.EndElement: //Display the end of the element.
                         textBox1.Text = XReader.Name.ToString();                        
                        break;
                }
            }                
            }
           
           // textBox1.Text = XmlStr.ToString();
           
                                    
            }                
        }

        private void label13_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            
                    

        }






    }
}

It sounds as if you just need to iterate through files in a directory.
Here is an example of that:

using System;
using System.IO;

namespace DW_FileLoop
{
   class Program
   {
      static void Main(string[] args)
      {
         string strRootDir = @"C:\Users\Mark\Documents\VoteResults2";
         string[] arr_strFiles = Directory.GetFiles(strRootDir, "*.xml");

         foreach (string strFile in arr_strFiles)
         {
            Console.WriteLine("Processing: " + strFile);
            //Call XML Processor here.
         }
      }
   }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.