There is a companyList list built on the basis of the query, it contains the names of companies, and there is a directoryList built on DirectoryInfo. As in linq, add a condition for matching directory names with names in the companyList list.
List<string> companyList = new List<string>(); using (SqlCommand addToCompanyList = new SqlCommand("SELECT [PROV_LATNAME] FROM [dbfTo1c].[dbo].[FileFormat]")) { addToCompanyList.Connection = new SqlConnection(Connection.dbfTo1c_ConectionString); addToCompanyList.Connection.Open(); SqlDataReader reader = addToCompanyList.ExecuteReader(); while (reader.Read()) companyList.Add(Convert.ToString(reader["PROV_LATNAME"])); //listBox1.DataSource = companyList; reader.Close(); addToCompanyList.Connection.Close(); } DirectoryInfo[] directoryList = new DirectoryInfo(path) .EnumerateDirectories() .Where(dirInfo => Regex.IsMatch(dirInfo.Name, searchP)) .ToArray();
Where- GrundyIntersect()method. something likevar result = first.Select(x=>x.Name).Intersect(second.Select(x=>x.Name)). - Bald