Hi jon,
I have checked your code. There is no problem with your code. Its working as expected.
Check this example. Now please take its reference and correct your code.
XMLFile1.xml
<?xml version="1.0" standalone="yes"?>
<Employees>
<Employee Id="1" City="Seattle">
<EmployeeName>Nancy Davolio</EmployeeName>
<Country>USA</Country>
</Employee>
<Employee Id="2" City="Tacoma">
<EmployeeName>Andrew Fuller</EmployeeName>
<Country>USA</Country>
</Employee>
<Employee Id="3" City="Kirkland">
<EmployeeName>Janet Leverling</EmployeeName>
<Country>USA</Country>
</Employee>
</Employees>
XMLFile2.xml
<?xml version="1.0" standalone="yes"?>
<Employees>
<Employee Id="4" City="Redmond">
<EmployeeName>Margaret Peacock</EmployeeName>
<Country>USA</Country>
</Employee>
<Employee Id="5" City="London">
<EmployeeName>Steven Buchanan</EmployeeName>
<Country>UK</Country>
</Employee>
<Employee Id="6" City="London">
<EmployeeName>Michael Suyama</EmployeeName>
<Country>UK</Country>
</Employee>
</Employees>
C#
protected void Page_Load(object sender, EventArgs e)
{
IEnumerable<string> filesUploaded = System.IO.Directory.EnumerateFiles(Server.MapPath("~/SFA_XML_Upload/"), "*")
.Select(f => System.IO.Path.GetFileName(f));
int ordcliRowsInserted = 0;
foreach (var file in filesUploaded)
{
string filename = Server.MapPath("~/SFA_XML_Upload/" + file);
var doc = System.Xml.Linq.XDocument.Load(filename);
Response.Write(doc.ToString());
}
}
Output
Nancy Davolio USA Andrew Fuller USA Janet Leverling USA Margaret Peacock USA Steven Buchanan UK Michael Suyama UK