Reputation: 55
I am using the FolderBrowserDialog to select the Folder where user can save file. While opening the folder browse dialog, application get crashed and raised below exception.
System.InvalidOperationException: Unable to retrieve the root folder.
at System.Windows.Forms.FolderBrowserDialog.RunDialog(IntPtr hWndOwner)
at System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)
at TestApp.GenerateExcelReport()
Users are using the applications from cloud as My application is launched on Citrix Environment. Hence not all the users has facing this issue but few of them are facing.
string folderPath = "X:\\Reports";
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
FolderBrowserDialog folderDialog = new FolderBrowserDialog();
folderDialog.ShowNewFolderButton = true;
folderDialog.SelectedPath = folderPath;
DialogResult dialogResult = folderDialog.ShowDialog();
if (dialogResult == DialogResult.OK)
{
folderPath = folderDialog.SelectedPath;
}
else
{
return;
}
Kindly suggest what can be the root cause of getting this issue while showing the FolderBrowseDialog. Also, suggest the potential fixes to prevent this exception.
Thanks & Regards,
Hiren Lad
Upvotes: 1
Views: 1195
Reputation: 23
I'm late but the fix for this issue might be if you set the RootFolder property of FolderBrowserDialog other than the default RootFolder. e.g
FolderBrowserDialog folderDialog = new FolderBrowserDialog();
folderDialog.RootFolder = Environment.SpecialFolder.MyComputer;
Upvotes: 0
Reputation: 618
This occurs for me when the folder %USERPROFILE%\Desktop
doesn't exist. Creating that folder resolved the issue. Note that File Explorer may show a Desktop folder in %USERPROFILE%
even if Desktop doesn't actually exist. You can verify whether Desktop exists by running dir %USERPROFILE%
in cmd
.
Upvotes: 1