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);
}