Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Im trying to actually match the file names from a database with the filenames of a directory. I have stored the filenames from the database into an array. This array consist of multiple filenames selected upon a certain criteria. Now I'm supposed to match these filenames with the filenames from the directory. If the filename matches/exists then I'll display the file to the user for downloading. Any help?......
Posted
Updated 30-Jul-12 12:24pm
v4
Comments
TRK3 30-Jul-12 18:26pm    
You pretty much posted the same question already: http://www.codeproject.com/Questions/428339/Compare-File-names-in-database-with-directory-list

What have you tried?

What specifically are you haveing trouble with?

1 solution

This would be one way to do it, there would be countless of other ways.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
   class Program
   {
      static void Main(string[] args)
      {
         List<string> filenamesFromDatabase = new List<string>();
         List<string> filenamesFromDirectory = new List<string>();

         filenamesFromDatabase.Add("firstfile.txt");

         filenamesFromDirectory.Add("firstfile.txt");
         filenamesFromDirectory.Add("anotherfile.txt");

         foreach (string filename in filenamesFromDirectory)
         {
            if (filenamesFromDatabase.Any(s => filename.Contains(s)))
            {
               //Display the file to the user for downloading here
               Console.WriteLine(filename);
            }
         }

         Console.ReadLine();
      }
   }
}


Output: firstfile.txt
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900