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

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...

            }
This article has been dead for over six months. Start a new discussion instead.