Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have got this line of code to get all files of Xml that are downloaded on my server
C#
string[] fileEntries = Directory.GetFiles(Server.MapPath("~/SavedFolder/" +  Session["Username"].ToString() + "//"));


currently i am using XmlDocument to load each file name in the file entries
i want a faster way to read these Xml any suggestion how can i use Xml Reader or any other Xml tool .

What I have tried:

currently i am using

C#
    string[] fileEntries = Directory.GetFiles(Server.MapPath("~/SavedFolder/" +  Session["Username"].ToString() + "//"));

foreach(string fileName in fileEntries)
 {

  XmlDocument xml = new XmlDocument();
  xml.Load(@fileName)
 }
Posted
Updated 18-May-16 7:16am
v2
Comments
OriginalGriff 18-May-16 5:33am    
How slow are we talking here?
What have you measured it as taking?
How often is this done?
How many files?
Himaan Singh 18-May-16 5:39am    
files are around 100 each of 1 mb each
Kornfeld Eliyahu Peter 18-May-16 5:39am    
Are you only reading the files or do something else with that XML you just read in? Did you broke apart the time, to see if it spent on the reading part or on the processing part?
Himaan Singh 18-May-16 5:45am    
what i do is read different nodes from the xml and store that information in a list
Kornfeld Eliyahu Peter 18-May-16 5:46am    
That's only partly answers my question - what about the timing?

1 solution

Maybe something like this, you can select the nodes that are needed this way:
C#
using (var xmlTextReader = new XmlTextReader(fileNameXml))
{
    while (xmlTextReader.Read())
    {
        switch (xmlTextReader.NodeType)
        {
            case XmlNodeType.Element: // The node is an element (group).
                Debug.Print(@"<" + xmlTextReader.Name + @">");
                break;

            case XmlNodeType.Text:

                Debug.Print(xmlTextReader.Value);
                break;

            case XmlNodeType.EndElement: // Display the end of the element.
                Debug.Print(@"</" + xmlTextReader.Name + @">");
                break;
        }
    }
}
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900