Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to match selected files from the folder browser to hide rows from the gridview which is already saved in SQL database?

Here i am using gridview to display file names from the user selected path using browse button and those selected files are saved into database. Now again when user browse the same path, I want to hide file names from the gridview that is already saved in database.
Posted
Updated 10-Dec-13 17:27pm
v3
Comments
Aydin Homay 7-Dec-13 0:02am    
Hi
Your question is not clear because I don`t know you want to the hide file name or you want to the hide path from gridview and I don`t know your file name in different column with file path or they both in same column please review your question and add additional comments
SukirtiShetty 7-Dec-13 0:50am    
I want to hide file names from gridview and I will save only file names into database.

Here now I do not need file names which is already in database, when I select same folder for the next time.
Member 10451599 7-Dec-13 15:10pm    
Can you provide code where you are binding gridview?
SukirtiShetty 8-Dec-13 22:35pm    
FilePath = TextBox1.Text;
DataTable dt = new DataTable();
dt.Columns.Add("ImageName", typeof(System.String));
DataRow dr = null;
DirectoryInfo dir = new DirectoryInfo(FilePath);
foreach (FileInfo fi in dir.GetFiles())
{
dr = dt.NewRow();
dr[0] = fi.Name.ToString();
dt.Rows.Add(dr);

}

ImageGridView.DataSource = dt;
ImageGridView.DataBind();

1 solution

C#
      // Imagine that we have only stored the names of a.txt, b.csv and c.png
      // Further; pretend that from here...
      List<string> storedFileList = new List<string>();
      storedFileList.AddRange(new string[] {"a.txt", "b.csv", "c.png"});

      DataTable storedFiles = new DataTable();
      storedFiles.Columns.Add(new DataColumn("filename", typeof(string)));
      foreach (string name in storedFileList)
      {
        storedFiles.LoadDataRow(new object[] {name}, true);
      }
      // ...to here is the DB query that retrieves the previously stored filenames and 
      // dumps them into a datatable (or dataview).

      var qryAlreadyStored = from DataRow r in storedFiles.Rows
                             select r["filename"];

      // Now just filter out the files that we've already seen listing them
      // in ascending alphabetical order.
      string path = @"C:\TheDirectory\PathThat\WeAre\InterestedIn";
      DirectoryInfo dir = new DirectoryInfo(path); 
      var qryFile = from FileInfo file in dir.GetFiles()
                    where !qryAlreadyStored.ToList().Contains(file.Name)
                    orderby file.Name ascending
                    select file.Name; 
      
      // Reuse the same table structure for our grid.
      DataTable filesToDisplay = storedFiles.Clone();
      foreach (string newName in qryFile) 
      {
        filesToDisplay.LoadDataRow(new object[] {newName}, true);
      }

      TheGrid.DataSource = filesToDisplay;
      TheGrid.DataBind();

</string></string>
 
Share this answer
 
v3

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