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

  • Home
  • SEARCH
  • 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 7807973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:01:00+00:00 2026-06-02T03:01:00+00:00

I am using the following code to loop through a directory, looking for xml

  • 0

I am using the following code to loop through a directory, looking for xml files and readind them in:

XmlReader reader = null;

foreach (string file in files)
{
   try
   {
     System.IO.FileInfo fi = new System.IO.FileInfo(file);

     string fext = fi.Extension;
     if (fext == ".xml")
     {
         Console.WriteLine("Processing file:" + fi.Name);
         reader = XmlReader.Create(fi.Name);
       **//BUT THIS WORKS---> reader = new XmlReader(@"\\10.00.100.11   \Data\Cognos\ReportOutput\Test\Risk Rating Exception Detail (LN-133-D)-en-us_2012-04-14T031017814Z-pdf_desc.xml");**

          while (reader.Read())
          {
              switch (reader.NodeType)
              {
                 case XmlNodeType.Element: // The node is an element.
                      Console.Write("<" + reader.Name);
                      Console.WriteLine(">");
                      break;
                 case XmlNodeType.Text: //Display the text in each element.
                      Console.WriteLine(reader.Value);
                      break;
                 case XmlNodeType.EndElement: //Display the end of the element.
                      Console.Write("</" + reader.Name);
                      Console.WriteLine(">");
                      break;
              }

           }

           reader.Close();

       }

    }
    catch (System.IO.FileNotFoundException e)
    {
     // If file was deleted by a separate application or thread since the call to TraverseTree() then just continue.
         Console.WriteLine(e.Message);
         continue;
    }

}

When I use XML.Create on the single file (see BUT THIS WORKS), I can read everything in that document. When I use it with fi.Name, I get to see the message “Processing file: “, then, for every single xml file in the directory, I see “Could not find file ‘C:\Documents and Settings\\My Documents\Visual Studio 2010\Projects\MoveReportsTest\MoveReportsTest\bin\Debug\.

I tried moving the reader instantiation around, at first, it was instantiated for every file, I tried moving the reader.Close() around, thinking I can’t instantiate the same reader for every file, but it didn’t change anything (same error). The ‘could not find file message is not coming from any catch phrase… I am clueless… please help! Thanks!

  • 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-02T03:01:01+00:00Added an answer on June 2, 2026 at 3:01 am

    As you refer to fi.Name it picks just the name of the file. If you in the path you provide only the name of the file, the default path will be the folder where you binaries are, so that one you see in exception : C:\Documents and Settings\\My Documents\Visual Studio 2010\Projects\MoveReportsTest\MoveReportsTest\bin\Debug\.

    Pass complete path to the XML file you gonna read => fi.FullName.

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

Sidebar

Related Questions

I'm using the following code to loop through a directory to print out the
I'm using the following code to loop through a multidimensional array and find users
I have been using the following code to loop through specific classes in my
I usually loop through lines in a file using the following code: open my
I'm using the following code to loop through couple of links from my database,
I have a package i am using the foreach loop to loop through the
I have the following bit of code: // Loop through returned data and write
When I run the following code: // Loop through each store and update shopping
Given the following method,where I pass configuration byref, then loop through it using a
Using following code I try to get updated list of checkbuttons' corresponding text values,

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.