So the issue I'm having is if a xml file contains "ONE" then it should move to the credit directory, else move to debit directory. Here is my current solution:
private void SplitAndMoveCreditCamts(FileInfo f)
{
if (v.Elements().Contains(x => x.Value == "ONE"))
WriteToDirectory(v, "ONE\\");
else
WriteToDirectory(v, "TWO\\");
}
It does move the files to just the TWO directory. This means that the "WriteToDirectory" method is working, but ignores the "ONE" condition. I believe the error lies there.
I think that your issue lies within the element line (v.Elements().Contains(x => x.Value == "ONE"))
The best solution for you is to make two seperate methods, ONE and TWO, where your SplitAndMoveONE
is called.
private void SplitAndMoveONE(FileInfo f)
{
XElement[] els = GetXmlMessages(f.Name);
foreach (var v in els)
{
XNamespace ns = v.Name.Namespace;
bool exists = v.Descendants(ns + "ONE")
.Select(item => item.Value);
if (exists)
WriteToDirectory(v, "ONE\\");
else
// give error message
}
}
Namespace is vital in order to find the elements in your tag. The same applies to TWO.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With