Hi Guys i am getting error directory name is invalid.My codeis as follows :

private void toolStripButton1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            parser = new GrammarParser();
            parser.showStep += new GrammarParser.ShowStep(parser_showStep);
            if (dialog.ShowDialog() == DialogResult.OK)
            {

                string[] names = Directory.GetFiles(dialog.FileName);
                for (int i = 0; i < names.Length; i++)
                {
                    // read file to the string
                    string text = "";
                    parser.Text = text;
                   resultString = parser.SerParserString;
                    
                    //   go to to database

                }
            }
        }

Thanks for any help

Plzzz help me guys!!!!!!!!!:(

please give some help for get file names

The open file dialog returns a file name.
Directory.GetFiles expects a path to a directory, not a file.
Use the folderBrowserDialog instead, something like this:

private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                string folderName = folderBrowserDialog1.SelectedPath;
                string[] names = Directory.GetFiles(folderName);
                //more code...

            }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.