I have an XML file which is generated from a windows application like below "Repport.xml":
<ArrayOfAutoReportXML>
<AutoReportXML ReportName="Report1" ReportID="1" />
<AutoReportXML ReportName="Report2" ReportID="2" />
<AutoReportXML ReportName="Report3" ReportID="3" />
<AutoReportXML ReportName="Report4" ReportID="4" />
<AutoReportXML ReportName="Report5" ReportID="5" />
</ArrayOfAutoReportXML>
I am trying to check if ReportName already exists and i am trying below code to do that:
using (FileStream fs = new FileStream("Repport.xml", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
XDocument doc = XDocument.Load(fs);
string attrReportname = (string) doc.Elements("AutoReportXML")
.Where(ox => ox.Attribute("ReportName").Value.ToString() == ReportName)
.FirstOrDefault();
}
And attrReportName is null.