c# program to read xml files in a directory

I I need the C# code to do the following
1.Scan every directory(including sub directories) between 3/15/2011 and now
2.Read any file that starts with "Status....xml
3.Look for the status tag in the XML. Example <Status> </status>
3.Write the directory path,the status to a text file if the status is not <Status>Success</status>
wademiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alfred A.Commented:
Try the following.   Don't forget to add System.IO and System.Xml.  I hope this helps.
using System.IO;
using System.Xml;

private void Form1_Load(object sender, EventArgs e)
{    
    string[] filenames = Directory.GetFiles(@"C:\YourDir", "Status*.xml", SearchOption.AllDirectories);
    foreach (string p in filenames)
    {
       FileInfo fi = new FileInfo(p);
       string StatusStr = string.Empty;
       DateTime dt;
       bool isOK = DateTime.TryParse("03/15/2011",out dt);
       if((fi.LastWriteTime.CompareTo(dt) >= 0) && (fi.LastWriteTime.CompareTo(DateTime.Now) <= 0))
       {
           //Read XML File
           XmlDocument doc = new XmlDocument();
           doc.Load(p);
           XmlNodeList elemList = doc.GetElementsByTagName("Status");
           for (int i = 0; i < elemList.Count; i++)
           {
               StatusStr = elemList[i].InnerXml;
           };
           if (StatusStr != "Success")
           {
               File.AppendAllText(@"C:\Test\result.txt", p);
               File.AppendAllText(@"C:\Test\result.txt", StatusStr);
           }
       }
    }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fernando SotoRetiredCommented:
This question is a duplicate post that has been already asnwered here; http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_26943392.html
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.