Click here to Skip to main content
15,303,572 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to compare the file names from the database and compare that names with the file name present in the directory list.
I have successfully filter out the file names from the database but now I am stuck on how to compare it with the directory list file name.
If the names matche, then I want to display the file in the checkboxlist..
I have started it with this code......
SqlConnection sqlCon = new SqlConnection("Server=FNUEXCPC01\\SQLSERVER2005;Database=PREMIUM;Trusted_Connection=yes;");
            //sqlCmd.Connection = sqlCon;

            //SqlDataReader myReader;

            string sql = "Select Ref_Link from RECORDSMG where Department = '" + ddview.SelectedValue + "'and School= '" 
                          + ddlistschools.SelectedValue + "' and Doc_Category = '" + ddcat.SelectedValue + "'";
            SqlCommand sqlCmd = new SqlCommand();
            sqlCmd.Connection = sqlCon;
            sqlCmd.CommandType = CommandType.Text;
            sqlCmd.CommandText = sql;
            SqlDataReader myReader = sqlCmd.ExecuteReader();
            while (myReader.Read())

               // returnValue.Add(myReader.GetString(0));

                var test2 = myReader;

                //var test = chk;
              //  Response.Write(test);

1 solution

I would read them from the database into a list, and sort it (or use the Sql ORDER BY clause to do that for you).
You can then read the folder content using:
string[] files = Directory.GetFiles(path,searchPattern,SearchOption.TopDirectoryOnly)
If you then sort these into the same order as the database list, it is a relatively simple matter to compare them.

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