1

I am developing my C# application in Visual C# Express 2010 and when i was opening the FolderBrowserDialog, it was opened fine and also i could able to get the folder name and files.

The same application (also i didn't changed any single line of code), i have opened in Visual Studio 2010 ultimate. While debugging the application, i didn't get any issues.

But, while opening the FolderBrowserDialog through application(when clicking Radio button), application has closing automatically without any error(i have the code in try-catch itself. not even getting any exception).

Here is my simple code which closing the application:

DialogResult getFolderDialogResult = folderBrowserDialog1.ShowDialog();

while commenting the above, application is not closing.

Note: i just added the openFileDialog before calling folderBrowserDialog, i wonder, it is working fine.

openFileDialog1.ShowDialog();
DialogResult getFolderDialogResult = folderBrowserDialog1.ShowDialog();

One more Note: i have created the new project and tried the FolderBrowserDialog. It is working fine :(

My Code:

        try
        {
            MessageBox.Show("Select Folder Radio Button CLicked", "Radio Button", MessageBoxButtons.OK);
            string[] getFilesList = null;
            listBoxSelectSheetsMFR.DataSource = getFilesList;

            if (listBoxSelectSheetsMFR.Items.Count > 0)
            {
                listBoxSelectSheetsMFR.Items.Clear();
            }

            String tempString = "";
            ArrayList onlyFileNames = new ArrayList();
            String invalidFormat = "No";
            String folderPath = "";
            //Open Folder Selection Dialog
            DialogResult getFolderDialogResult = folderBrowserDialog1.ShowDialog();

            if (getFolderDialogResult == DialogResult.OK)
            {
                folderPath = folderBrowserDialog1.SelectedPath;
                MessageBox.Show(folderPath, "Folder Path", MessageBoxButtons.OK);

                //Get All Files
                getFilesList = Directory.GetFiles(folderPath);

                for (int i = 0; i < getFilesList.Length; i++)
                {
                    if (!Path.GetExtension(getFilesList[i].ToString()).Equals(".xls"))
                    {
                        invalidFormat = "Yes";
                    }
                }

                if (invalidFormat.Equals("No"))
                {
                    panelSelectSheetsMFR.Visible = true;

                    //Enable the ListBox and load the filenames
                    for (int i = 0; i < getFilesList.Length; i++)
                    {
                        tempString = getFilesList[i].ToString().Replace(folderPath + "\\", "");
                        onlyFileNames.Add(tempString.Replace(".xls", ""));
                    }

                    //Adding Items into ListBox
                    listBoxSelectSheetsMFR.DataSource = onlyFileNames;
                }
                else
                {
                    MessageBox.Show("One of file is having invalid Format. Please make sure all files \nshould be .xls format.", "Format Error", MessageBoxButtons.OK);
                }
            }
            MessageBox.Show(getFilesList.Length.ToString(), "# of Files", MessageBoxButtons.OK);
        }
        catch (Exception selectFolderExMsg)
        {
            MessageBox.Show(selectFolderExMsg.ToString(), "selectFolderRadioButtonFN", MessageBoxButtons.OK);
        }
decyclone
  • 30,394
  • 6
  • 63
  • 80
Pon
  • 315
  • 1
  • 5
  • 10
  • 2
    I would suggest first, that you clean out your bin directories and rebuild. failing that try building with a newer version of .net and see if that helps – Matthew Layton Nov 11 '12 at 07:29
  • show us how folderBrowserDialog1 is defined – Flot2011 Nov 11 '12 at 07:29
  • use try and catch around it and see if anything pops up – Prix Nov 11 '12 at 07:37
  • clean out the Bin and rebuild is not helping. Also i tried with .Net 3.5 and .Net 4...nothing works... – Pon Nov 11 '12 at 07:41
  • @Flot2011 definition: private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1; i hope you are expecting this line.... – Pon Nov 11 '12 at 07:41
  • @Prix: My code is already in try-catch block....no exceptions thrown.... – Pon Nov 11 '12 at 07:44
  • @Pon: Note related to your question but I recommend using `foreach` loops instead of `for` loops. – decyclone Nov 11 '12 at 08:00
  • 1
    here's another post for the same issue: http://stackoverflow.com/questions/8897076/folderbrowserdialog-crashes-the-application – Hardrada Nov 11 '12 at 10:48
  • Hey all, i tried the same code in different pc and it works fine...i think my laptop Visual studio having some problems...anyway i switched from laptop to PC....thanks to all :) – Pon Nov 12 '12 at 08:07
  • can you upload your project somewhere? – VladL Jan 20 '13 at 13:00
  • Maybe your VS is crashing due to insufficient memory of your hardware? I guess.. haha – Jack Frost Aug 29 '13 at 03:01

0 Answers0