LINQ with Two Data Sets

M

MitchW

Hello,

1. I have an XML file that lists filenames (i.e., a.txt, b.txt, c.txt,
etc.). I have loaded this into a LINQ var anonymous type.

2. I also have a DirectoryInfo set in another var type. This contains a
listing of all files in a certain directory.

What I ultimately need is a list of all the filenames from "1" above and if
there is a match in item "2" I need the LastWriteTime of the file. I then
need to display this in a GridView or something.

What is the best most efficient approach?

thanks,
mitch
 
M

Mythran

MitchW said:
Hello,

1. I have an XML file that lists filenames (i.e., a.txt, b.txt, c.txt,
etc.). I have loaded this into a LINQ var anonymous type.

2. I also have a DirectoryInfo set in another var type. This contains a
listing of all files in a certain directory.

What I ultimately need is a list of all the filenames from "1" above and
if
there is a match in item "2" I need the LastWriteTime of the file. I then
need to display this in a GridView or something.

What is the best most efficient approach?

thanks,
mitch

Well, a little more info may be required to help ya ... but as a start, here
is an example:

string[] fileNames = new string[] {
"a.txt", "b.txt", "c.txt"
};
DirectoryInfo di = new DirectoryInfo(@"C:\dev\test");
FileInfo[] files = di.GetFiles(@"*.txt");

var results =
from file in files where
fileNames.Contains(file.Name)
select new { file.LastWriteTime, file.Name };

foreach (var file in results) {
Console.WriteLine(
file.Name + "; " + file.LastWriteTime.ToString()
);
}

This doesn't take into account whether you have parsed the XML file or
not...

HTH,
Mythran
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top