Click here to Skip to main content
13,007,469 members (60,562 online)
Rate this:
Please Sign up or sign in to vote.
Hi All,

I am working on XML files. I have created small XML tool which returns number of specific tag repeated in all files.

This code runs properly to find the numbers of tag present in files within specific folder mean there should not be any other folder in XML files containing folder.

I am facing problem if there is any other folder or other type of file present in the XML files containing folder this programs fails.

The code is as follow:

public void SearchMultipleTags()
            if (txtSearchTag.Text != "")
                    //string str = null;
                    //XmlNodeList nodelist;
                    string folderPath = textBox2.Text;
                    DirectoryInfo di = new DirectoryInfo(folderPath);
                    FileInfo[] rgFiles = di.GetFiles("*.xml");
                    foreach (FileInfo fi in rgFiles)
                        int i = 0;
                        XmlDocument xmldoc = new XmlDocument();
                        //rtbox2.Text = fi.FullName.ToString();
                        foreach (XmlNode node in xmldoc.GetElementsByTagName(txtSearchTag.Text))
                            i = i + 1;
                        rtbox2.Text += DateTime.Now + "\n" + fi.FullName + " \nInstance: " + i.ToString() + "\n\n";
                        //rtbox2.Text += fi.FullName + "instances: " + str.ToString();
                catch (Exception)
                    MessageBox.Show("Invalid Path or Empty File name field.");
                MessageBox.Show("Dont leave field blanks.");

Please help in this.

Mayur Alaspure.
Posted 7-Oct-12 5:21am
Updated 7-Oct-12 5:22am
OriginalGriff 7-Oct-12 11:28am
What error or problem do you get?
Mayur2258 7-Oct-12 11:55am

Thanks for response i Checked it again and found that there was an entity text error in XML file thats why the code was failed. Now its working fine.
Thanks again for your interest.. :)

Can you suggest me on following:
My provided Code Search the specific tag in XML files.

Can you suggest me the code to search the specific Text in same XML files. ?
Milind Thakkar 8-Oct-12 1:43am
Please update you post with additional information and your "new" question in order to enable members to help you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170628.1 | Last Updated 7 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100