admin管理员组

文章数量:1291027

The OpenFileDialog() has this capability. I need the same capability in the FolderBrowserDialog().
For example, I want the area in the red box to be shown in the FolderBrowserDialog:

This is how I am currently calling it:

        /// <summary>
        /// Browse and select folder event handler.
        /// </summary>
        /// <param name="mopParameter">The mopParameter.</param>
        /// <param name="rowIndex">The index of the DataGridView row being edited.</param>
        private void FolderBrowserDialog_Open(MOPParameter mopParameter, Int32 rowIndex)
        {
            try
            {
                var cellValue = this.dataGridView.Rows[rowIndex].Cells[2].Value.ToString();
                var folderBrowserDialog = new FolderBrowserDialog
                {
                    SelectedPath = cellValue,
                };

                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                {
                    this.dataGridView.Rows[rowIndex].Cells[2].Value = folderBrowserDialog.SelectedPath;
                    MOPParameterUtil.MOPParameterSetValue(
                        this.mopParameters, mopParameter.ParameterName, folderBrowserDialog.SelectedPath);
                }

                folderBrowserDialog.Dispose();
            }
            catch (Exception e)
            {
                MessageBox.Show(
                    this,
                    @"Error selecting folder." + Environment.NewLine + e.Message,
                    @"Configure MOP Options",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
        }

The OpenFileDialog() has this capability. I need the same capability in the FolderBrowserDialog().
For example, I want the area in the red box to be shown in the FolderBrowserDialog:

This is how I am currently calling it:

        /// <summary>
        /// Browse and select folder event handler.
        /// </summary>
        /// <param name="mopParameter">The mopParameter.</param>
        /// <param name="rowIndex">The index of the DataGridView row being edited.</param>
        private void FolderBrowserDialog_Open(MOPParameter mopParameter, Int32 rowIndex)
        {
            try
            {
                var cellValue = this.dataGridView.Rows[rowIndex].Cells[2].Value.ToString();
                var folderBrowserDialog = new FolderBrowserDialog
                {
                    SelectedPath = cellValue,
                };

                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                {
                    this.dataGridView.Rows[rowIndex].Cells[2].Value = folderBrowserDialog.SelectedPath;
                    MOPParameterUtil.MOPParameterSetValue(
                        this.mopParameters, mopParameter.ParameterName, folderBrowserDialog.SelectedPath);
                }

                folderBrowserDialog.Dispose();
            }
            catch (Exception e)
            {
                MessageBox.Show(
                    this,
                    @"Error selecting folder." + Environment.NewLine + e.Message,
                    @"Configure MOP Options",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
        }
Share Improve this question edited Feb 20 at 16:09 Bruce B Wilson asked Feb 13 at 16:10 Bruce B WilsonBruce B Wilson 417 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You can use the System.Home CLSID: 679f85cb-0220-4080-b29b-5540cc05aab6 (you can find it in the Registry) to instruct the FolderBrowserDialog to set the InitialDirectory to the Quick Access path, adding the shell::: prefix.

Simple example:

using var fbDialog = new FolderBrowserDialog() { 
    InitialDirectory = "shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}" 
};
fbDialog.ShowDialog();

The same CLSID is used in both Windows 10 and Windows 11, but I've tested this in Windows 10 only

The dotted CLSID form, .{Some Special Folder CLSID} does not work here.

This of course (given the Property used), refers to .NET's FolderBrowserDialog, not the class exposed by .NET Framework

本文标签: winformsHow can I include the quotQuick Accessquot pane in the FolderBrowserDialog() in cStack Overflow