I want to search all files in particular folder and add those files into data grid view in C#. I have two text box and two buttons. The first button browse the folder and textbox1 select folder path and textbox2 want search all the doc files click on second button and add the files into datagridview. plz help me.
-
I'm trying to understand your question... The part about adding files to a data grid view, no problem. The text box stuff, not so much.RQDQ– RQDQ2011-02-22 13:03:46 +00:00Commented Feb 22, 2011 at 13:03
-
"add those files into data grid view" ?? Add the content of the files? List the names of the files?user226555– user2265552011-02-22 14:46:53 +00:00Commented Feb 22, 2011 at 14:46
Add a comment
|
2 Answers
Here is my guess at what you're looking for:
//Assume that textbox1 has folder path
DataGridView1.DataSource = Directory.GetFiles(textbox1.Text);
1 Comment
hometoast
This was exactly my guess as well.
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Multiselect = true;
openFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
if(openFileDialog.ShowDialog() == true)
{
foreach(string filename in openFileDialog.FileNames)
datagrid.Items.Add(Path.GetFileName(filename));
}