I am using the CommonOpenFileDialog in the Windows Code Code Pack as a folder selection dialog. I set the InitialDirectory property to Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments). However, when I show the dialog, the path in the address bar will be Libraries \ Documents (not C: \ users \ craig \ my documents, as I expected). In addition, if I just click on the “Select Folder” button, I get a dialog that says “You have selected a library. Instead, select a folder.
Does anyone know why my path to the file is ignored, in favor of "libraries \ documents"? More importantly, how can I make the dialog respect the passed value of InitialDirectory?
The code I use for dialogue is:
if (CommonFileDialog.IsPlatformSupported)
{
var folderSelectorDialog = new CommonOpenFileDialog();
folderSelectorDialog.EnsureReadOnly = true;
folderSelectorDialog.IsFolderPicker = true;
folderSelectorDialog.AllowNonFileSystemItems = false;
folderSelectorDialog.Multiselect = false;
folderSelectorDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
folderSelectorDialog.Title = "Project Location";
if (folderSelectorDialog.ShowDialog() == CommonFileDialogResult.Ok)
{
ShellContainer shellContainer = null;
try
{
shellContainer = folderSelectorDialog.FileAsShellObject as ShellContainer;
}
catch
{
MessageBox.Show("Could not create a ShellObject from the selected item");
}
FilePath = shellContainer != null ? shellContainer.ParsingName : string.Empty;
}
}
Thank,
-Craig
Craig source
share