I want to make a project in which more than one xml files will be processed at once .In this project I tried to put xml files in array and then I used but always I get errors.My code is like that:
string[] files = { "ilk.xml", "migr.xml", "caa.xml" };
public Form1()
{
InitializeComponent();
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(@"c:\markets\");
count = dir.GetFiles("*.xml").Length;
for (int d = 0; d < count; d++)
{
XmlDocument xmlDoc1 = new XmlDocument();
xmlDoc1.Load(files[d]);
xmldocument= new XmlDocument();
xmldocument.Load(@"C:\\markets\files[d]");
//here I compare the values of xml files
}
the error is “Could not find file ‘C:\markets\files[d]”.All the xml files are in the markets directory.When I wrote the file name without using array there is no problem .Can you help me?
You could use async loading and multi-threading if your really want to load them “at once” (as in, parallel at the same time). Probably though you want to just have all the XML documents parsed and loaded at the same time based on your comment that you will be comparing them. How about using an array of XmlDocument objects to match the input array of file names? This is the simplest way to load them all. You could use a collection too if you need that to be dynamic.
This code also allows you get retrieve all the files with “.xml” extension in the directory. This seems like something you are trying to do with the count, but then you reference the staticly defined file name array. This would result in an error if the number of XML files in that directory exceeded the file names in your array.
If you wanted just to use a fixed set of names, then you could do this: