I've got two arrays where I want to find all the elements in Array0 where the full string from Array1 is contained in the string of Array0. Here is the scenario:
I've got a string array that contains the full path of all the xml files in a certain directory. I then get a list of locations and only want to return the subset of xml file paths where the filename of the xml file is the loc id.
So, my Array0 has something like:
c:\some\directory\6011044.xml
c:\some\directory\6028393.xml
c:\some\directory\6039938.xml
c:\some\directory\6028833.xml
And my Array1 has:
6011044
6028833
...and I only want to have the results from Array0 where the filepath string contains string from Array1.
Here is what I've got...
filesToLoad = (from f in Directory.GetFiles(Server.MapPath("App_Data"), "*.xml")
where f.Contains(from l in locs select l.CdsCode.ToString())
select f).ToArray();
...but I get the following compiler error...
Argument '1': cannot convert from 'System.Collections.Generic.IEnumerable<string>' to 'string'
...which I can understand from an English standpoint, but do not know how to resolve.
Am I coming at the from the wrong angle?
Am I missing just one piece?
EDIT
Here is what I've changed it to:
filesToLoad = (Directory.GetFiles(Server.MapPath("App_Data"), "*.xml"))
.Where(path => locs.Any(l => path.Contains(l.CdsCode.ToString()))
).ToArray();
...but this still gets me all the .xml files even though one of them is not in my locs entity collection. What did I put in the wrong place?
Obviously I'm missing the main concept so perhaps a little explanation as to what each piece is doing would be helpful too?
Edit 2 See Mark's comment below. The answer to my problem, was me. I had one record in my locs collection that had a zero for the CDS value and thus was matching all records in my xml collection. If only I could find a way to code without myself, then I'd be the perfect developer!