LINQ with Two Data Sets

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?TWl0Y2hX?=

    LINQ with Two Data Sets

    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
  • Mythran

    #2
    Re: LINQ with Two Data Sets



    "MitchW" <MitchW@discuss ions.microsoft. comwrote in message
    news:9B6F23A3-16FC-43EF-8D74-E5AE7EF68725@mi crosoft.com...
    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\tes t");
    FileInfo[] files = di.GetFiles(@"* .txt");

    var results =
    from file in files where
    fileNames.Conta ins(file.Name)
    select new { file.LastWriteT ime, file.Name };

    foreach (var file in results) {
    Console.WriteLi ne(
    file.Name + "; " + file.LastWriteT ime.ToString()
    );
    }

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

    HTH,
    Mythran

    Comment

    Working...