2

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.

2
  • 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. Commented 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? Commented Feb 22, 2011 at 14:46

2 Answers 2

2

Here is my guess at what you're looking for:

//Assume that textbox1 has folder path
DataGridView1.DataSource = Directory.GetFiles(textbox1.Text);
Sign up to request clarification or add additional context in comments.

1 Comment

This was exactly my guess as well.
0
 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));
                    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.