I have tried several methods, none of which appear to work...
You can see the different methods I have tried by taking a look at the commented lines of code, but I am able to get the attribute fine, and newIndex
is updated properly, but then when I go to change the attribute called count
it doesn't do anything.
XmlElement reports = (XmlElement)doc.SelectSingleNode("//Reports");
XmlAttribute reportCount = (XmlAttribute)doc.SelectSingleNode("//Reports/@count");
int count = Convert.ToInt32(reportCount.Value);
newIndex = count + 1;
//doc.DocumentElement.SetAttribute("count", "\"" + newIndex.ToString() + "\"");
//reportCount.Value = newIndex.ToString();
reports.SetAttribute("count", newIndex.ToString());
XML File
<?xml version="1.0" encoding="utf-8"?>
<Reports count="1"><!--this count should be equal to the last id-->
<Report id="1">
<Workbook>APG0214.xlsx</Workbook>
<Filepath>\\fileserver\homeshares\POS Reports</Filepath>
</Report>
<Report id="2">
<Workbook>CBM0214.xlsx</Workbook>
<Filepath>\\fileserver\homeshares\POS Reports</Filepath>
</Report>
</Reports>
Any help is appreciated!